加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs产品列表源码

发布时间:2020-12-17 08:43:26 所属栏目:安全 来源:网络整理
导读:angular.module('product',[]) .service('productData',function () { return [ { id:333,name:'ipone',price:5400 },{ id:8845,name:'ipad',price:3420 },{ id:980,name:'imac',price:15400 },{ id:1212,name:'ipad air',price:2300 },{ id:3424,name:'ipad

angular.module('product',[])
    .service('productData',function () {
        return [
            {
                id:333,name:'ipone',price:5400
            },{
                id:8845,name:'ipad',price:3420
            },{
                id:980,name:'imac',price:15400
            },{
                id:1212,name:'ipad air',price:2300
            },{
                id:3424,name:'ipad mini',price:2200
            }
        ]
})
    .controller('productController',function ($scope,productData) {
        $scope.productData = productData;
        $scope.orderType = 'id';
        $scope.order = '-';
        
        $scope.changOrder = function (type) {
            $scope.orderType = type;
            if($scope.order === ''){
                $scope.order = '-';
            } else {
                $scope.order = '';
            }
        }
    })
调用:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../vendor/bootstrap3/css/bootstrap.min.css">
    <style>
        .orderColor{
            color:red;
        }
    </style>
</head>
<body>
    <div ng-app="product">
        <div class="container" ng-controller="productController">
            <nav class="navbar navbar-default">
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <form class="navbar-form navbar-left">
                        <div class="form-group">
                            <input type="text" ng-model="search.id" class="form-control" placeholder="Search">
                        </div>
                    </form>
                </div>
            </nav>
            <table class="table">
                <thead>
                    <tr>
                        <th ng-click="changOrder('id')" ng-class="{dropup:order === ''}">
                            产品编号
                            <span ng-class="{orderColor:orderType === 'id'}" class="caret"></span>
                        </th>
                        <th ng-click="changOrder('name')" ng-class="{dropup:order === ''}">
                            产品名称
                            <span ng-class="{orderColor:orderType === 'name'}" class="caret"></span>
                        </th>
                        <th ng-click="changOrder('price')" ng-class="{dropup:order === ''}">
                            产品价格
                            <span ng-class="{orderColor:orderType === 'price'}" class="caret"></span>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-repeat="product in productData | filter : search | orderBy:order+orderType">
                        <td>{{product.id}}</td>
                        <td>{{product.name}}</td>
                        <td>{{product.price | currency : '¥ '}}</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <script type="text/javascript" src="../vendor/angular/angularjs.js"></script>
    <script type="text/javascript" src="./app/index.js"></script>
</body>
</html>
效果图:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读