每当局部变量的值发生更改时,我想调用一个函数。 我使用 while 循环尝试了这段代码,但我被锁定在循环中。
var titleChanged = false;
$scope.$watch('title',function(newValue, oldValue) {
if (newValue !== oldValue) {
titleChanged = true;
}
});
while (true) {
$timeout(checkForChangeAndSave, 3000);
};
function checkForChangeAndSave() {
if(titleChanged) {
updateNote();
titleChanged = false;
}
}
function updateNote() {
notesService.update($stateParams.id, {title: $scope.title});
notesService.getAll();
};
最佳答案
关于javascript - 如何检查局部变量随时间的变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31577191/