ng-repeat無法顯示重複元素的解法

<p ng-repeat="num in [1,1,1]">{{num}}</p>

會出現ERROR訊息"duplicates in a repeater are not allowed",
因為ng-repeat不允許重複元素。

解決方法

<p ng-repeat="num in [1,1,1] track by $index">{{num}}</p>

1

1

1

留言

這個網誌中的熱門文章

AngularJS (1) 宣告ng-app

href with relative url 在錨點使用相對路徑