AngularJS Tutorial - Change a Model Value by Controller Function








The following code shows how to change a Model Value by Controller Function.

Example


<!doctype html>
<html ng-app>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script>
    <script>
function MyCtrl($scope) {<!--from   w  w  w  . j av a  2 s.  c o m-->
  $scope.value = 1;

  $scope.incrementValue = function(value) {
    $scope.value += 1;
  };
}    
    </script>
    <link rel="stylesheet" href="css/bootstrap.css">
  </head>
  <body ng-app>
    <div ng-controller="MyCtrl">
      <p ng-init="incrementValue(5)">{{value}}</p>
    </div>
  </body>
</html>

The code above is rendered as follows: