Use ng-change to change scope value

Description

The following code shows how to use ng-change to change scope value.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<script type='text/javascript'>
function Ctrl($scope, $window) {<!-- ww  w .j a v a  2s . c o m-->
    $scope.window = $window;
}
</script>
</head>
<body>
  <div ng-app ng-controller="Ctrl">
  <label>Name:</label>
  <input type="text"  
         ng-model="yourNameInput" 
         placeholder="Enter a name here" 
         ng-change="window.yourName = yourNameInput">
  <input type="button" onClick="console.log(yourName);" value="Log">
  <hr>
  <h1 ng-bind-template="Hello, {{yourNameInput}}"></h1>
</div>
</body>
</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities