Monday, 19 October 2015

ng-bind

What is ng-bind: ng-bind used to show value of given expression.ng-bind has one-way binding unlike ng-model(which has two-way binding); .

Description of ng-bind: As it is mentioned earlier that ng-bind has one-way binding ,So it is useful to show value of a expression in html element. In normal situation as we used {{myexpression}} to show value of expression (can not use in eveery where like that) ,but ng-bind is more effective manner to show angularjs expression's value. show we have not face rendering problem (later will discuss in ng-cloak)

Syntax of ng-bind:
<div ng-bind="myexpression"></div>
Or

<input ng-bind="myexpression" /> etc.

How to Use ng-bind/ng-bind Example:
AngularJs Example 1:

<div ng-cick="msg='This is angularjs example of ng-bind'"></div>
<div ng-init="myexpression='This is angularjs example of ng-bind'">
    <div ng-bind="myexpression">
    </div>
</div>
  o/p: This is angularjs example of ng-bind

AngularJs Example 2:
   <div ng-app="webapp">
       <div ng-controller="angularjsexampleCtlr">
           <div ng-bind="myexpression">
           </div>
       </div>

</div>
<script>
    angular.module('webapp', []).controller('angularjsexampleCtlr', function ($scope, $http) {
        $scope.myfun = function () {
            alert("This is angularjs example of ng-bind another way");
        }
    });
</script>


  o/p:   This is angularjs example of ng-bind another way

No comments :

Post a comment