watch比较消耗性能,所以用完后就要消除监听
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>作用域</title>
<script src="js/angular.min.js"></script>
<style type="text/css">
</style>
</head>
<body ng-app="my-frist-app">
<div id="box" ng-controller="fristController" >
商品数量:<input type="text" ng-model="count"/>
商品单价:<input type="text" ng-model="price" />
商品总价:{{count*price}}
邮费:{{youFei}}
总计:<p ng-bind="total"></p>
</div>
<script type="text/javascript">
var myApp = angular.module('my-frist-app',[])
// $watch 监听方法,监听变化
myApp.controller('fristController',function($scope){
// $scope.$watch('price*count',function(){
// console.log("fuji")
// });
var watch = $scope.$watch('price',function(newValue,oldValue,$scope){
console.log(newValue);
console.log(oldValue)
})
// 销毁监听
// watch();
});
</script>
</body>
</html>