如何从 $scope.watch 函数内部调用 Controller 中的函数? 我尝试过类似的方法,但这不起作用
$scope.$watch(function(){return self.user}, function (newVal, oldVal, scope){
if (self.user) {
getNotificationCount();
}
});
var getNotificationCount = function(){
console.log("called your function");
}
它给我一个错误
TypeError: getNotificationCount is not a function
最佳答案
调用前需要先定义getNotificationCount
。
var getNotificationCount = function(){
console.log("called your function");
}
$scope.$watch(function(){return self.user}, function (newVal, oldVal, scope){
if (self.user) {
getNotificationCount();
}
});
关于javascript - 从 Angular watch 中调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40798989/