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.
– Lollipop
Don’t put the attribute
ng-repeat
in thespan
. That way there won’t be aspan
for each element in the word list.– mutlei
so far so good, but as I add to the input this sequence of values?
– Lollipop
You want a
input
for all words? Or ainput
for one word at a time?– mutlei
An input with several words separated by commas, as I add, through another input.
– Lollipop
Can you replicate this problem in a Jsfiddle or Jsbin? Maybe then we can help.
– mutlei
@mutlei, you are here > http://jsfiddle.net/aohegdnr/
– Lollipop
This solves the problem? http://jsfiddle.net/tn224w2d/
– mutlei
Very interesting, can inside an input and separated by comma? hug
– Lollipop