Watch variable and change it

前端 未结 5 1687
广开言路
广开言路 2020-12-24 07:10

In AngularJS I have a directive that watches a scope variable. When the variable contains certain data then I need to alter that variable a bit. The problem is that when I c

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-24 07:35

    yes you can cancel it like this

    var wathcer = scope.$watch('someVar', function(newValue, oldValue) {
        console.log(newValue);
        scope.someVar = [Do something with someVar];
    
    });
    wathcer(); // clear the watch
    

提交回复
热议问题