<script type="text/javascript">
var app = angular.module("myApp",[]);
app.controller("myController",function($scope,$http){
$http.post("${pageContext.request.contextPath}/goods/selectAll")
.success(function(obj){
$scope.goods=obj;
})
$scope.reduce=function(index){
var gid = $scope.goods[index].gid;
$http.post("${pageContext.request.contextPath}/goods/reduce?gid="+gid)
.success(function(){
--$scope.goods[index].count;
if($scope.goods[index].count<1){
if(confirm("确定删除吗?")){
$scope.goods.splice(index,1);
alert("删除成功!");
$http.post("${pageContext.request.contextPath}/goods/delete?gid="+gid)
}
}
})
}
$scope.add=function(index){
var gid = $scope.goods[index].gid;
$http.post("${pageContext.request.contextPath}/goods/jia?gid="+gid)
.success(function(){
++$scope.goods[index].count;
})
}
})
</script>
</head>
<body ng-app="myApp">
<div ng-controller="myController" class = "container">
欢迎 <span style="color: red">${user.name}</span> 登录
<h2 style="color: red" align="center">购物车页面</h2>
<table class = "table table-striped table-bordered table-hover">
<thead>
<tr class = "success">
<td>选择</td>
<td>商品id</td>
<td>商品名称</td>
<td>商品价格</td>
<td>商品数量</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="g in goods">
<td>
<input type="checkbox" value="{{g.gid}}">
</td>
<td>{{g.gid}}</td>
<td>{{g.gname}}</td>
<td>{{g.price}}</td>
<td>
<input class="btn btn-primary" type="button" value="-" ng-click="reduce($index)">
<input type="text" value="{{g.count}}" style="width: 30px;">
<input class="btn btn-primary" type="button" value="+" ng-click="add($index)">
</td>
</tr>
</tbody>
</table>
<input class="btn btn-danger" type="button" value="添加到购物车" id="mai">
</div>
</body>
var app = angular.module("myApp",[]);
app.controller("myController",function($scope,$http){
$http.post("${pageContext.request.contextPath}/goods/selectAll")
.success(function(obj){
$scope.goods=obj;
})
$scope.reduce=function(index){
var gid = $scope.goods[index].gid;
$http.post("${pageContext.request.contextPath}/goods/reduce?gid="+gid)
.success(function(){
--$scope.goods[index].count;
if($scope.goods[index].count<1){
if(confirm("确定删除吗?")){
$scope.goods.splice(index,1);
alert("删除成功!");
$http.post("${pageContext.request.contextPath}/goods/delete?gid="+gid)
}
}
})
}
$scope.add=function(index){
var gid = $scope.goods[index].gid;
$http.post("${pageContext.request.contextPath}/goods/jia?gid="+gid)
.success(function(){
++$scope.goods[index].count;
})
}
})
</script>
</head>
<body ng-app="myApp">
<div ng-controller="myController" class = "container">
欢迎 <span style="color: red">${user.name}</span> 登录
<h2 style="color: red" align="center">购物车页面</h2>
<table class = "table table-striped table-bordered table-hover">
<thead>
<tr class = "success">
<td>选择</td>
<td>商品id</td>
<td>商品名称</td>
<td>商品价格</td>
<td>商品数量</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="g in goods">
<td>
<input type="checkbox" value="{{g.gid}}">
</td>
<td>{{g.gid}}</td>
<td>{{g.gname}}</td>
<td>{{g.price}}</td>
<td>
<input class="btn btn-primary" type="button" value="-" ng-click="reduce($index)">
<input type="text" value="{{g.count}}" style="width: 30px;">
<input class="btn btn-primary" type="button" value="+" ng-click="add($index)">
</td>
</tr>
</tbody>
</table>
<input class="btn btn-danger" type="button" value="添加到购物车" id="mai">
</div>
</body>