ng-repeat指令不显示任何内容

时间:2015-09-03 12:41:02

标签: angularjs

这是我的代码

HTML

<div ng-controller="moveController as vm">
<div ng-repeat="move in vm.moves">
    Move of the Week are <br />
    {{move}}
</div>

JS

function getMovesForCurrentWeek() {
       service.get("Move", "List").then(function (data) {
           vm.moves = data;
   });
}

vm.moves有类似这样的数据= [&#34; 4&#34;,&#34; 9&#34;,&#34; 27&#34;,&#34; 4&#34;, &#34; 1&#34;&#34; 28&#34;&#34; 9&#34;]

2 个答案:

答案 0 :(得分:0)

vm.moves有两次重复值4和9,因此无法进行映射,您需要通过$ index跟踪它。

尝试这个

<div ng-controller="moveController as vm">
<div ng-repeat="move in vm.moves track by $index">
    Move of the Week are <br />
    {{move}}
</div>

有用的链接

http://learnit.visrosoftware.com/Tutorial/Angular/angular-conditional-binding

$ index跟踪的示例。 http://learnit.visrosoftware.com/try/1LXjq60x

答案 1 :(得分:0)

您可以使用Track by: 请参见链接https://docs.angularjs.org/error/ngRepeat/dupes