AngularJS Tutorial - Read binded value from controller








The following code shows how to Read binded value from controller.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<script type='text/javascript'>
<!--from   w ww . j  a v  a  2 s. c  om-->
var app = angular.module("app", []);

app.controller("FormCtrl", ["$scope", function FormCtrl($scope) {
  $scope.submit = function() {
      $scope.submitValue = $scope.test;
  };
}]);
</script>
</head>
<body ng-app="app">
  <div ng-controller="FormCtrl">
    <input type="text" name="test" ng-model="test" />
    <button type="button" ng-click="submit()">Submit</button>
    Last submitted value: {{ submitValue }}
</div>
</body>
</html>

The code above is rendered as follows: