跳過相同的舊...我是新的bla bla ...
我有這種困惑,在我的代碼在下面給出,當我改變我的變量「watchVar」(最初將有10,但在不同的觀點)以當前代碼中顯示的方式,不觸發監視(如果它是一個事件,我不知道)。 (我可以確認通過日誌消息,沒有消息打印)
但是,當我切換語句2和9的註釋,$ watch的作品。
$scope.funcy = function(){
//$scope.watchVar=""; // Resetting So the watch on this variable calls a method
$http({
method : 'GET',
url : 'myUrl',
headers : {'Content-Type' : 'applicaiton/x-www-form-urlencoded'}
}).success(function(response){
if(response.response_code==1){
$scope.watchVar=""; // Resetting So the watch on this variable calls a method
$scope.mylist = response.results;
$scope.watchVar= $scope.mylist[0]; //gives 10
}
});
}
$scope.$watch('watchVar',function(){
console.log("watch watchVar : " + $scope.watchVar);
if(angular.isNumber($scope.watchVar)==true){
// call a func
}
});
我可以想到兩個原因。
- 相同變量的即時更改可能不會被監視捕獲。
- 如果更改是在塊或其他內容中實現的,則變量的最終更改不會實時反映,此處爲成功方法。
上述兩個陳述中的任何一個是否給出了這種行爲的原因,或者是否有任何其他原因,我顯然不知道。
再次同老.. thanx提前等等等等,P
編輯: 我寫了一大段試圖解釋我的方案,並意識到這將在嗯眼睛已經更多的痛苦...是啊眼睛比寫所有的。 因此刪除了。 我意識到我有其他的方法和解決方法。
只是好奇地想知道爲什麼我的一個場景工作,其他都沒有,當兩個人都做同樣的事情。如果被監視的表達式的值已改變自上次消化環
超出範圍的問題:爲什麼你需要在你的情況下觀察你的變量?承諾決議並沒有使你的案件的工作? – mfrachet