首页 > 其他 > 详细

angular 实现总价满100折扣

时间:2014-04-28 19:09:05      阅读:441      评论:0      收藏:0      [点我收藏+]

<div ng-controller="CartController">
<div ng-repeat="item in items">
<span>{{item.title}}</span>
<input ng-model="item.quantity" />
<span>{{item.price|currency}}</span>
<span>{{item.price*item.quantity|currency}}</span>
</div>
<div>total:{{totalCart()|currency}}</div>
<div>Discount:{{bill.discount|currency}}</div>
<div>Subtotal:{{subtotal()|currency}}</div>
</div>

 

 

var app=angular.module("myApp",[]);
app.controller("CartController",function($scope){
$scope.bill={};
$scope.items=[{title:"paint pots",quantity:8,price:3.98},
{title:"polka dots",quantity:17,price:13.65},
{title:"pebbles",quantity:5,price:6.85},
{title:"ppts",quantity:18,price:33.09},
{title:"papses",quantity:98,price:45.68},
];
$scope.totalCart=function(){
var total=0;
for(var i=0,len=$scope.items.length;i<len;i++){
total=total+$scope.items[i].price*$scope.items[i].quantity;
}
return total;
}
$scope.subtotal=function(){
return $scope.totalCart()-$scope.bill.discount;

}
function calculateDiscount(newValue){
return $scope.bill.discount=newValue>1000?100:0;
}

$scope.$watch($scope.totalCart,calculateDiscount);
});

angular 实现总价满100折扣,布布扣,bubuko.com

angular 实现总价满100折扣

原文:http://www.cnblogs.com/java-php/p/3693192.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!