add watch on a non scope variable in angularjs

后端 未结 3 1179
自闭症患者
自闭症患者 2021-02-01 06:10

Is there a way to add watch to a non scope variable. I want to add a watch to local variable. I have something like this

 function EditAssetRegistryController(as         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-01 06:35

    A cleaner syntax using ES6

    $scope.$watch(() => {
        return this.thingToWatch;
    }, (newVal, oldVal) => {
        // Your code here...
    });
    

提交回复
热议问题