Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

One way One Time and Two Way binding

<!doctype html>
<html ng-app="angular-app1">
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js"></script>
    
    
    <script>
        
    var app =angular.module("angular-app1",[]);
        app.controller('student',["$scope",function($scope){
            $scope.x=50;
            $scope.y=45;
        }]);
        
        app.controller('calcSum',["$scope",function($scope){
            $scope.doSum=function(){
                $scope.sum=parseInt($scope.x)+parseInt($scope.y);
            }
        }]);
        
    </script>
    
  </head>
  <body>
    <div ng-controller="student">
        The value of x is {{x}}, <input type="text" ng-model="x"> and <br>
        The value of y is {{y}} <input type="text" ng-model="y"> and <br>
        <hr>
        
        The value of x is <span ng-bind="x"></span><br>
        The value of y is <span ng-bind="y"></span>
        <div ng-controller="calcSum">
           <div><button type="button" ng-click="doSum()">Calculate Sum</button></div> 
            The Sum of X and Y is {{sum}}
            
            <hr>
            Intial value of x and y are {{::x}} and {{::y}}
        </div>
        
    </div>
  </body>
</html>

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.