Skip to content

Instantly share code, notes, and snippets.

@allenyang79
Created August 30, 2013 05:55
Show Gist options
  • Save allenyang79/6386697 to your computer and use it in GitHub Desktop.
Save allenyang79/6386697 to your computer and use it in GitHub Desktop.
angularjs deep watch test
.error{
color:#f00;
}
.warning{
color:#0f0;
}
.highlight{
background:#efefef;
}
<html = ng-app="app">
<body ng-controller="MyCtrl">
<div>
x:<input type="text" ng-model="data.x"/><br/>
y:<input type="text" ng-model="data.y"/><br/>
ans:<input type="text" ng-attr-value="ans();" value="{{ans()|currency}}"/><br/>
{{data.x*data.y}}
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
</body>
</html>
var app = angular.module('app',[]);
app.controller('MyCtrl', function($scope){
$scope.data={
x:0,
y:0
};
$scope.ans=function(){
return $scope.data.x*$scope.data.y;
};
$scope.$watch('data',function(newValue, oldValue, $scope){
//alert("X");
console.log("CHANGE");
},true);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment