【发布时间】:2014-10-02 20:11:18
【问题描述】:
我在 codepen 上有这个代码示例:http://codepen.io/anon/pen/hauvb
问题是 ng-repeat 在我将表单对象推送到数组后没有更新。我可以看到内容正在添加到数组中,但 ng-repeat 没有更新。我尝试使用 $apply 但我被告知我不需要它,因为 ng-click 为我更新了 $digest。任何帮助将不胜感激,以了解我所缺少的。谢谢。
var app = angular.module('theTasker', []);
app.controller('MyTasks', [function(){
this.tasks = [
{
title: "This is the title",
completed: false
},
{
title: "This is the title",
completed: true
},
{
title: "This is the title",
completed: false
}
];
this.myform = {
item: "Item Title",
completed: false
};
this.addtask = function(){
this.tasks.push(this.myform);
};
}])
编辑:
上面的代码产生了这个错误:
不允许在转发器中重复。使用“track by”表达式 指定唯一键。
【问题讨论】: