Angular 学习笔记——shop

<!DOCTYPE html>
<html lang="en" ng-app>
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script type="text/javascript" src="js/angular-1.3.0.js"></script>
	<script>
		function shop($scope){
			$scope.items = {
				"name":"apple",
				"price":"5",
				"quantity":"5",
				"fre":"10"	
			};

			$scope.sum = function (){
				return $scope.items.price * $scope.items.quantity;
			};

			$scope.$watch($scope.sum,function(newVal,oldVal){

				$scope.items.fre = newVal >= 100 ? 0 : 10;
			});
		}
	</script>
</head>
<body ng-controller="shop">
	<div >
		<span>{{items.name}}</span><br/>
		<span>{{items.price}}</span><br/>
		<input  type="text" ng-model="items.quantity"><br/>
		<span>{{items.fre  | currency:'¥' }}</span><br/>
		<span>{{sum() + items.fre | currency:'¥'}}</span>
	</div>
</body>
</html>

 

posted @ 2015-11-23 12:20  mayufo  阅读(165)  评论(0编辑  收藏  举报