Angularjs watch for change in parent scope

前端 未结 5 1746
甜味超标
甜味超标 2020-12-24 05:32

I\'m writing a directive and I need to watch the parent scope for a change. Not sure if I\'m doing this the preferred way, but its not working with the following code:

5条回答
  •  余生分开走
    2020-12-24 05:38

    If you're looking for watching a parent scope variable inside a child scope, you can add true as second argument on your $watch. This will trigger your watch every time your object is modified

    $scope.$watch("searchContext", function (ctx) {
                    ...
                }, true);
    

提交回复
热议问题