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>
原文地址:https://www.cnblogs.com/mayufo/p/4988023.html