我试图找出为什么我的$watch
未被触发。这是从相关的控制器的一个片段:
<span>There are {{tasks.length}} total tasks</span>
我缺少什么:
$scope.$watch('tasks', function (newValue, oldValue) {
//do some stuff
//only enters here once
//newValue and oldValue are equal at that point
});
$scope.tasks = tasksService.tasks();
$scope.addTask = function (taskCreationString) {
tasksService.addTask(taskCreationString);//modifies tasks array
};
在我看来,tasks
显然被正确,因为我已经其长度必然像这样更新?
这似乎是这个问题也适用于观看的对象。相反,你必须看一个特定的财产。 – VSO 2016-05-27 23:43:50