Created
August 30, 2013 05:55
-
-
Save allenyang79/6386697 to your computer and use it in GitHub Desktop.
angularjs deep watch test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.error{ | |
color:#f00; | |
} | |
.warning{ | |
color:#0f0; | |
} | |
.highlight{ | |
background:#efefef; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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