Watch variable and change it

前端 未结 5 1680
广开言路
广开言路 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:37

    Inside function use if condition to avoide continues for loop

    scope.$watch('someVar', function(newValue, oldValue) {
       if(newValue!==oldValue) {
        console.log(newValue);
        scope.someVar = [Do something with someVar];
       } 
    });
    

提交回复
热议问题