Sunday 20 August 2017

$scope.$watch()

$watch watch the activity happening when model and view changes just like on change event



<!-- ko with: home -->
<html>
<head>

    <script src="~/Scripts/angular.min.js"></script>
    <script src="~/Scripts/Customjs.js"></script>
</head>
<body ng-app="myapp">
  
    <div id="div2" ng-controller="Function2">
        Instance of {{ControllerName}} created
        <input  type="text" ng-model="mytext"/>
        {{mytext}}
          </div>
</body>

</html>



/// <reference path="angular.min.js" />
var app = angular.module("myapp", []);


function Function2($scope) {
    $scope.ControllerName = "Function2";
    $scope.$watch('mytext', function(newvalue, oldvalue) {
        console.log("new value=" + newvalue);
        console.log("old value=" + oldvalue);
    });
  
}

app.controller("Function2", Function2);



No comments:

Post a Comment