AngularJS $watch
Keep track of current model value by using $scope
Angular, AngularJS
by santhosh lanka
HTML
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<div ng-app="helloApp" ng-controller="helloCtrl">
<p>Name:
<input type="text" placeholder="your name" ng-model="myName">
</p>
<h1>Hello {{myName}}</h1>
<h2>{{updated_info}}</h2>
JavaScript
var app = angular.module("helloApp", []);
app.controller("helloCtrl", function ($scope) {
/* $scope.myName = "" */;
$scope.$watch("myName", function () {
$scope.updated_info = $scope.myName;
});
});