Dynamically populate input with angular

Asked

Viewed 2,505 times

0

Friends, help me make a script in which I can add words to an input as a button is clicked. The words should stand side by side and separated by comma:

word1, word2, word3

This gives me an input, as I add, with the value filled, but I don’t want to generate multiple inputs and yes only one with words, as in the example above:

<input type="text"  ng-model="palavra">

<div ng-click="addpalavra(palavra);">+</div>

<div ng-show="palavra">                                                             

<span ng-repeat="palavra in project.palavras track by $index" ng-show="$index>0 || $parent.$index>0">{{ palavra }} 

<input type="hidden" name="palavra[]" value ="{{palavra}}" ng-model="palavra" >

<script>
  $scope.palavra = function(palavra) {
      project.palavras.push(palavra);
        };
</script>

THIS IS AN EXAMPLE OF THE ABOVE CODE: http://jsfiddle.net/aohegdnr/

  • I offer reputation for your next question.

  • Don’t put the attribute ng-repeat in the span. That way there won’t be a span for each element in the word list.

  • so far so good, but as I add to the input this sequence of values?

  • You want a input for all words? Or a input for one word at a time?

  • An input with several words separated by commas, as I add, through another input.

  • Can you replicate this problem in a Jsfiddle or Jsbin? Maybe then we can help.

  • @mutlei, you are here > http://jsfiddle.net/aohegdnr/

  • 1

    This solves the problem? http://jsfiddle.net/tn224w2d/

  • Very interesting, can inside an input and separated by comma? hug

Show 4 more comments

1 answer

1


I don’t know if I understood what you want right. It would just display the tags, separated by ', ', within an input?

Would look like this:

<input class="form-control" value="{{ project.tags.join(', ') }}">

Example.

  • Always being a master in Angular, iuristona!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.