2016-09-18 56 views
0

时vm.loadStats被称为

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

为什么你把表达式放在数组中?有特别的原因吗? $ scope方法的角度文档。$ watch方法表示这个参数应该是一个字符串或者一个函数 – Ripley511

回答

0

角$范围对象有三个$手表方法:

  • $手表,走字符串或函数

  • $ watchGroup,以表达阵列

  • $ watchCollection,拍摄物体

您应该使用$scope.$watch('vm.propositions', ...);$scope.$watchGroup(['vm.propositions'], ...);

AngularJS Documentation on $scope

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) { 
... 
} 
+0

这很奇怪,这个解决方案不起作用,它不会被调用。 – user1260928

+0

无法工作,$ scope与'vm'不同:vm是对控制器的引用,而$ scope是...对$ scope的引用!不要将'$ scope'与'this'混淆,它们在Angular中完全不同 – Ripley511