AngularJS 购物车实例

html 页面

<!DOCTYPE html>
<html ng-app>
<head>
	<title>Angular.js</title>
	<script type="text/javascript" src="angular-1.3.0.js"> </script>
	<script type="text/javascript" src="test.js"></script>
</head>
<body ng-controller="CartController">

<div ng-repeat="item in items">
<h3>your order</h3>
<span>{{item.title}}</span>
<input type="text" ng-model="item.quantity">
<span>{{item.price | currency}}</span>
<span>{{item.price * item.quantity | currency}}</span>
<button ng-click="remove($index)">remove</button>
</div>
</body>
</html>


 

js页面

function CartController($scope){
	$scope.items = [
		{title:"paint posts", quantity:"8", price:"7.8"},
		{title:"paint posts", quantity:"8", price:"7.8"},
		{title:"paint posts", quantity:"8", price:"7.8"}
	];

	$scope.remove = function(index){
		$scope.items.splice(index,1);
	}
}	

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。