AngularJS : Basic $watch not working

后端 未结 3 1511
鱼传尺愫
鱼传尺愫 2020-12-15 06:13

I\'m attempting to set up a watch in AngularJS and I\'m clearly doing something wrong, but I can\'t quite figure it out. The watch is firing on the immediate page load, but

3条回答
  •  鱼传尺愫
    2020-12-15 07:10

    You can use without $interval and $timeout

    $scope.$watch(function() {
                return variableToWatch;
            }, function(newVal, oldVal) {
                if (newVal !== oldVal) {
                    //custom logic goes here......
                }
            }, true);
    

提交回复
热议问题