2016-09-18 60 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