Angular One way binding
Angular default two way binding feature is awesome. I am personally a fan of angular two way data binding. But not always we would like to make use of it. Moreover unnecessary usage of it might degrade performance because of watchers and digest cycles associated with it.
Angular provides you an easy way to avoid two way data binding and adapt one way data binding wherever required. Prefixing "::" will makes data binding one way.
When you start typing text in the textbox, the text in span tag will not be updated due to one way binding.
We can use one way binding along with ng-repeat directive as well.
<ul>
<li ng-repeat="no in ::nos">
{{no}}
</li>
</ul>
Angular provides you an easy way to avoid two way data binding and adapt one way data binding wherever required. Prefixing "::" will makes data binding one way.
JS:
var app=angular.module('app',[])
.controller('myCtrl',function($scope){
$scope.msg="one way binding";
});HTML:
<input type="text" ng-model="msg"/>
{{::msg}}
When you start typing text in the textbox, the text in span tag will not be updated due to one way binding.
We can use one way binding along with ng-repeat directive as well.
<ul>
<li ng-repeat="no in ::nos">
{{no}}
</li>
</ul>
Comments
Post a Comment