angularjs - Lifecycle of angular controller -
i have angular controller
angular.module('partherapp') .controller('myctrl', function ($scope) { $scope.logtoconsole = function() { console.log('here am.'); }; });
and view:
<div ng-controller="myctrl"> {{logtoconsole()}} </div>
when application get's opened in browser can see tree times 'here am.'
. i'd expected once. ideas why happens?
it expected behaviour in angularjs, {{}}
(interpolation) directive call on each digest cycle , evaluates there expression. interpolation directive of angular directive gets evaluated when digest cycle run eg. ng-bind
, ng-show
, ng-class
, ng-if
, etc.
if want execute binding code once need use bindonce directive ::
& code be
<div ng-controller="myctrl"> {{::logtoconsole()}} </div>
detailed explaination how binding work in angularjs?
Comments
Post a Comment