Template node with ng-repeat won't show array items

Ok, it's the repetition. The array cannot contain the same value twice. ["a","a","a"] fails silently, ["a","b","c"] works. Why is this?

Edit: Error: ngRepeat:dupes - Duplicate Key in Repeater

Duplicate keys are banned because AngularJS uses keys to associate DOM nodes with items.

Wow. Funny how I've never run into this before - I've been tinkering w. Node-RED on & off for years. A somewhat surprising feature of Angular.JS which probably should be mentioned in any ng-repeat tuts & boilerplate. Might save someone else the headache. The solution (if your array may contain duplicate values) is to tell Angular to generate DOM references by index instead:

<table>
    <tr ng-repeat="value in msg.payload track by $index">
        <td>{{value}}</td>
    </tr>
</table>

Edit 2: And of course all this can be seen in the JS error console, plain as day - the error message even includes a link to the article on Angular's website... Doh!

3 Likes