web前端

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
    <script src="index.js"></script>
</head>

<body>
    <center>
        <div class="container" ng-app="product" ng-controller="productController">
            <!--导航栏-->
            <nav>
                <div >
                    <div id="bs-example-navbar-collapse-1">
                        <div>
                            <input type="text" ng-model="search" placeholder="产品名称">
                                  产品价格:
                                <select>
                                    <option>1000-2000</option>
                                </select>
                        </div>
                    </div>
                </div>
            </nav><br />
            <table border="1 solid" cellpadding="10" cellspacing="0">
                <thead>
                    <tr>
                        <th ng-click="sortProduct('id')">
                            产品编号
                            <span></span>
                        </th>
                        <th ng-click="sortProduct('name')">
                            产品名称
                            <span></span>
                        </th>
                        <th ng-click="sortProduct( 'price')">
                            产品价格
                            <span></span>
                        </th>
                        <th>
                            操作
                            <span></span>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-repeat="item in productList | filter:{ 'name':search} | orderBy:(orderSign+orderColumn) ">                        
                        <td>
                            {{item.id}}
                        </td>
                        <td>
                            {{item.name}}
                        </td>
                        <td>
                            {{item.price | currency:'(RMB)'}}
                        </td>
                        
                        <td>
                            <button ng-click="delProduct(item.name)">删除</button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </center>
</body>

</html>



angular.module('product',[])  
    .factory('productList',function(){  
        return [  
            { id:910,name:"imac",price:15400 },  
            { id:80,name:"iphone",price:5400 },  
            { id:29,name:"ipad",price:1420 },  
            { id:500,name:"ipad air",price:2340 },  
            { id:1200,name:"ipad mini",price:2200 }  
        ]
    })
    .controller('productController',function($scope,productList){
        /*$scope.search = "ipad";//定义一个变量
        alert($scope.search);*/
        $scope.productList=productList/*[  
            { id:910,name:"imac",price:15400 },  
            { id:80,name:"iphone",price:5400 },  
            { id:29,name:"ipad",price:1420 },  
            { id:500,name:"ipad air",price:2340 },  
            { id:1200,name:"ipad mini",price:2200 }  
        ]*/;  
 
        $scope.orderColumn='name'; //排序字段  
        $scope.orderSign='-';      //为空时正序 为负号时倒序  
 
        $scope.sortProduct=function(sortColumn){  //点击列标题排序事件  
            $scope.orderColumn=sortColumn;//觉得按照那一列进行排序  
            if($scope.orderSign=="-"){  
                $scope.orderSign="";
            }else{  
                $scope.orderSign='-';
            }
        };
        //删除产品
        $scope.delProduct = function(name){
            //alert(name);
            if(name!=""){
                if(confirm("是否删除"+name+"商品") ){
                    var p;
                    for (index in $scope.productList) {
                        p = $scope.productList[index];
                        if(p.name == name){
                            $scope.productList.splice(index,1);
                        }
                    }
                }
            }
        }
    });



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值