Sunday, September 21, 2014

AngularJS One-Time Binding

One-time binding is added at v1.3.

For this to work, just start the expression with two colons "::" ,

 <!doctype html>  
 <html lang="en">  
 <head>  
  <meta charset="UTF-8">  
  <title>Example - example-example95-production</title>  
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.2/angular.min.js"></script>  
  <script type="text/javascript">  
   angular.module("ng").run(function($rootScope){  
    $rootScope.GetMyValue = function() {  
     return $rootScope.MyValue;   
    }  
   })  
  </script>  
 </head>  
 <body ng-app>  
   <input type="text" ng-model="MyValue"/><br/>  
   MyValue = {{ MyValue }}<br/>  
   ::MyValue = {{ ::MyValue }} <br/>  
   GetMyValue() = {{ GetMyValue() }} <br/>  
   ::GetMyValue() = {{ ::GetMyValue() }} <br/>  
 </body>  
 </html>  

sample output,