Use `this.$watch` instead of `$scope.$watch` with 'Controller As'

后端 未结 4 1724
Happy的楠姐
Happy的楠姐 2021-02-20 06:44

Currently I am using the Controller As format for scoping controllers.

This works great for keeping the scope of values on the views clear and easy to follo

4条回答
  •  半阙折子戏
    2021-02-20 07:22

    Try this,

     $scope.$watch(angular.bind(this, function () {
                return this.contacts;
            }), function (newValue, oldValue) {
                console.log((newValue + '  -  ' + oldValue));
            });
    

提交回复
热议问题