I have this line of code in my AngularJS template:
<span ng-repeat="letter in word">{{letter}} </span>
'word' is a string. It works fine unless word contains the same letter twice. For example for the word 'boy' it works fine and renders the string "b o y ", but for the words 'ball' or 'elephant' nothing is rendered. The same problem occurs when iterating over an array of one letter strings.
Any ideas?
You can consider using transclusion inside a custom directive, to achieve the behavior you are looking for without using ng-repeat.
The ng-repeat directive repeats a set of HTML, a given number of times. The set of HTML will be repeated once per item in a collection. The collection must be an array or an object. Note: Each instance of the repetition is given its own scope, which consist of the current item.
Note: The $index variable is used to get the Index of the Row created by ng-repeat directive. Each row of the HTML Table consists of a Button which has been assigned ng-click directive. The $index variable is passed as parameter to the GetRowIndex function.
Change your repeater to use this:
<span ng-repeat="letter in word track by $index">{{letter}} </span>
Docs: http://docs.angularjs.org/error/ngRepeat/dupes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With