Both
ng-model and ng-bind directives provide binding features, the difference is that
ng-model provides 2 way data binding between the model and the view, while
ng-bind provides only one way binding between model and view.
While using ng-model the model is initially bound to the view when the page loads, any further changes made to the view will get automatically updated in the model object.
While using ng-bind the model is initially bound to the view when the page loads, any further changes made to the view will not get updated in the model object.
The below example demonstrates the difference between using ng-model and ng-bind to bind the model to the view.
ng-model
<div ng-init="Name='FirstName, LastName'">
Enter Name: <input type="text" ng-model="Name"><br/><br/>
Your Name is :{{Name}}
</div>
While using ng-model the model is initially bound to the view when the page loads, any further changes made to the view will get automatically updated in the model object.
While using ng-bind the model is initially bound to the view when the page loads, any further changes made to the view will not get updated in the model object.
The below example demonstrates the difference between using ng-model and ng-bind to bind the model to the view.
ng-model
<div ng-init="Name='FirstName, LastName'">
Enter Name: <input type="text" ng-model="Name"><br/><br/>
Your Name is :{{Name}}
</div>
ng-bind
<div ng-init="Name='FirstName, LastName'">
Enter Name: <input type="text" ng-bind="Name"><br/><br/>
Your Name is :{{Name}}
</div>
No comments:
Post a Comment