标签:
<!DOCTYPE HTML> <html ng-app> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> <script src="angular.min.js"></script> <script> function Aaa($scope,$timeout){ $scope.iphone = { money : 5000, num : 1, fre : 10 }; $scope.sum = function(){ return $scope.iphone.money * $scope.iphone.num; }; /*$scope.$watch(‘iphone.money‘,function(newVal,oldVal){ //iphone.money这里表示监听的是money这个输入框 console.log(newVal); //计算后的值,被监听的那个的值 console.log(oldVal); //计算前的值,被监听的那个的值 },true);*/ $scope.$watch($scope.sum,function(newVal,oldVal){ //$watch监听的意思,还可以监听函数 //console.log(newVal); //console.log(oldVal); $scope.iphone.fre = newVal >= 100 ? 0 : 10; }); } </script> </head> <body> <div ng-controller="Aaa"> <p>价格:<input type="text" ng-model="iphone.money"></p> <p>个数:<input type="text" ng-model="iphone.num"></p> <p>费用:<span>{{ sum() | currency:‘¥‘ }}</span></p> <!--currency 这是一个过滤器,货币格式化的方法,默认是美元符号--> <p>运费:<span>{{iphone.fre | currency:‘¥‘}}</span></p> <p>总额:<span>{{ sum() + iphone.fre | currency:‘¥‘}}</span></p> </div> </body> </html>
标签:
原文地址:http://www.cnblogs.com/LO-ME/p/4564029.html