<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="../AngularJS/angular.js"></script>
<script>
var app = angular.module("myApp",[]);
app.controller("myCtrl",function($scope){
$scope.products = [{
id:80,
name:"iphone",
price:5400
},{
id:1200,
name:"ipad mini",
price:2200
},{
id:500,
name:"ipad air",
price:2340
},{
id:29,
name:"ipad",
price:1420
},{
id:910,
name:"imac",
price:15400
}];
$scope.sortFlag = "-";
$scope.sortName = "name";
$scope.sortProducts = function(clomnName){
$scope.sortName = clomnName;
if($scope.sortFlag == "-"){
$scope.sortFlag = "";
}else{
$scope.sortFlag = "-";
}
}
$scope.deleteProduct = function(name){
// alert(name);
for(index in $scope.products){
if($scope.products[index].name == name){
$scope.products.splice(index,1);
}
}
}
$scope.deleteAll = function(){
$scope.products = null;
}
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
<input type="text" ng-model="search" />
<button ng-click="deleteAll()">全部删除</button><br/><br/>
<table border="1 solde" cellspacing="0" cellpadding="10">
<thead>
<tr>
<th ng-click="sortProducts('id')">产品编号</th>
<th ng-click="sortProducts('name')">产品名称</th>
<th ng-click="sortProducts('price')">产品价格</th>
<th>功能</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="goods in products | filter:search | orderBy:(sortFlag+sortName) ">
<td>{{goods.id}}</td>
<td>{{goods.name}}</td>
<td>{{goods.price}}</td>
<td><button ng-click="deleteProduct(goods.name)">删除</button></td>
</tr>
</tbody>
</table>
</center>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="../AngularJS/angular.js"></script>
<script>
var app = angular.module("myApp",[]);
app.controller("myCtrl",function($scope){
$scope.products = [{
id:80,
name:"iphone",
price:5400
},{
id:1200,
name:"ipad mini",
price:2200
},{
id:500,
name:"ipad air",
price:2340
},{
id:29,
name:"ipad",
price:1420
},{
id:910,
name:"imac",
price:15400
}];
$scope.sortFlag = "-";
$scope.sortName = "name";
$scope.sortProducts = function(clomnName){
$scope.sortName = clomnName;
if($scope.sortFlag == "-"){
$scope.sortFlag = "";
}else{
$scope.sortFlag = "-";
}
}
$scope.deleteProduct = function(name){
// alert(name);
for(index in $scope.products){
if($scope.products[index].name == name){
$scope.products.splice(index,1);
}
}
}
$scope.deleteAll = function(){
$scope.products = null;
}
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
<input type="text" ng-model="search" />
<button ng-click="deleteAll()">全部删除</button><br/><br/>
<table border="1 solde" cellspacing="0" cellpadding="10">
<thead>
<tr>
<th ng-click="sortProducts('id')">产品编号</th>
<th ng-click="sortProducts('name')">产品名称</th>
<th ng-click="sortProducts('price')">产品价格</th>
<th>功能</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="goods in products | filter:search | orderBy:(sortFlag+sortName) ">
<td>{{goods.id}}</td>
<td>{{goods.name}}</td>
<td>{{goods.price}}</td>
<td><button ng-click="deleteProduct(goods.name)">删除</button></td>
</tr>
</tbody>
</table>
</center>
</body>
</html>