我的$ scope。当调用vm.loadStats时,不会触发$ watch
var vm = this;
vm.loadStats = function(){
vm.propositions = null;
DateUtils.convertLocalDateToServer(vm.dateDebut);
vm.dateFinSever = DateUtils.convertLocalDateToServer(vm.dateDebut);
vm.propositions = PropositionsAffaireBetweenPropositionDates.get({dateDebut : vm.dateDebutServer, dateFin : vm.dateFinSever});
}
$scope.$watch(['vm.propositions'], function(newValues, oldValues) {
...
}
如果有人知道为什么......
感谢
答案 0 :(得分:0)
Angular $ scope对象有三个$ watch方法:
$ watch,接受字符串或函数
$ watchGroup,采用一系列表达式
$ watchCollection,拿一个对象
您应该使用$scope.$watch('vm.propositions', ...);
或$scope.$watchGroup(['vm.propositions'], ...);
答案 1 :(得分:0)
您的代码没有问题......这是一个小修复
//Note how I dropped "vm." prefix? its redundant because the strings you provide
//inside the array are translated into $scope.[yourScopedVariable]
$scope.$watch(['propositions'], function(newValues, oldValues) {
...
}