我试图弄清楚为什么我$watch
的没有被触发。这是来自相关控制器的片段:
$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
显然正在正确更新,因为我的长度限制如下:
<span>There are {{tasks.length}} total tasks</span>
我错过了什么?