Reputation: 407
If a ng-model changed in View, the $scope will be updated correspondingly, but if there is a {{x()}} in the View and a $scope.x=function(){} in the js part, is it that when any event or stuff happens in the view, the x() will be triggered?
I am not quite clear about the principle of AngularJs' event and functioning.
Upvotes: 0
Views: 174
Reputation: 5973
Most of the times Angular will properly handle $scope.x=function(){} and update views automatically.
That's because there are only a few moments in application execution time when your code is executed such as page load, AJAX callback etc. Angular knows about such moments and does dirty checking (comparing scope values before and after).
However, there might be times when Angular doesn't aware that you updating scope properties, for example when you integrating with some 3rd party plugins. In such cases you need to wrap your code, which changes scope properties in $scope.$apply method:
$scope.$apply(function(){
$scope.x = function(){};
});
Upvotes: 1