博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AngularJS实现产品列表(页面搜索,排序)
阅读量:6264 次
发布时间:2019-06-22

本文共 2914 字,大约阅读时间需要 9 分钟。

标签属性介绍

ng-class="{className:expression}" 如果expression为true,则使用className这个class。

ng-click="functionName(pram)" 这跟onclick是一样的,点击就执行functionName(pram)。

ng-repeat="i in set | filter:filterExpression or filterFunction| orderBy:order+orderType" 循环set里的元素,有过滤条件和排序条件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<
html
>
 
<
head
>
    
<
meta 
charset
=
"utf-8"
>
    
<
link 
href
=
"http://cdn.bootcss.com/bootstrap/3.3.4/css/bootstrap.min.css" 
rel
=
"stylesheet"
>
    
<
style 
type
=
"text/css"
>
    
body {
        
font-family: "Arial", "Microsoft YaHei", "黑体", "宋体", sans-serif;
    
}
     
    
.orderColor {
        
color: red;
    
}
    
</
style
>
</
head
>
 
<
body 
ng-app
=
"product"
>
    
<
div 
class
=
"container" 
ng-controller
=
"firstController"
>
        
<
nav 
class
=
"navbar navbar-inverse"
>
            
<
div 
class
=
"container-fluid"
>
                
<!-- Collect the nav links, forms, and other content for toggling -->
                
<
div 
class
=
"collapse navbar-collapse" 
id
=
"bs-example-navbar-collapse-1"
>
                    
<
form 
class
=
"navbar-form navbar-left" 
role
=
"search"
>
                        
<
div 
class
=
"form-group"
>
                            
<
input 
type
=
"text" 
class
=
"form-control" 
placeholder
=
"查找内容" 
ng-model
=
"search"
>
                        
</
div
>
                    
</
form
>
                
</
div
>
            
</
div
>
        
</
nav
>
        
<
table 
class
=
"table"
>
            
<
thead
>
                
<
tr
>
                    
<
th 
ng-class
=
"{dropup:order===''}" 
ng-click
=
"changeOrder('id')"
>产品名称<
span 
class
=
"caret" 
ng-class
=
"{orderColor:orderType==='id'}"
></
span
></
th
>
                    
<
th 
ng-class
=
"{dropup:order===''}" 
ng-click
=
"changeOrder('name')"
>产品编号<
span 
class
=
"caret" 
ng-class
=
"{orderColor:orderType==='name'}"
></
span
></
th
>
                    
<
th 
ng-class
=
"{dropup:order===''}" 
ng-click
=
"changeOrder('price')"
>产品价格<
span 
class
=
"caret" 
ng-class
=
"{orderColor:orderType==='price'}"
></
span
></
th
>
                
</
tr
>
            
</
thead
>
            
<
tbody
>
                
<
tr 
ng-repeat
=
"item in productData | filter:search | orderBy:order+orderType"
>
                    
<
td
>`item`.`id`</
td
>
                    
<
td
>`item`.`name`</
td
>
                    
<
td
>{
{item.price | currency:'RMB '}}</
td
>
                
</
tr
>
            
</
tbody
>
        
</
table
>
    
</
div
>
    
<
script 
src
=
"http://cdn.bootcss.com/angular.js/1.4.0-rc.2/angular.min.js"
></
script
>
    
<
script 
type
=
"text/javascript"
>
    
angular.module('product', [])
        
.service('productData', function() {
            
return [{
                
id: 1098,
                
name: 'iPhone',
                
price: 5288
            
}, {
                
id: 5420,
                
name: 'iPad',
                
price: 4388
            
}, {
                
id: 2067,
                
name: 'Mac Book',
                
price: 10888
            
}, {
                
id: 5991,
                
name: 'Surface',
                
price: 9288
            
}];
        
})
        
.controller('firstController', function($scope, productData) {
            
$scope.productData = productData;
            
$scope.orderType = 'id';
            
$scope.order = '-';
            
$scope.changeOrder = function(type) {
                
$scope.orderType = type;
                
if ($scope.order === '') {
                    
$scope.order = '-';
                
} else {
                    
$scope.order = '';
                
}
            
}
        
});
    
</
script
>
</
body
>
 
</
html
>
本文转自 iampomelo 51CTO博客,原文链接:http://blog.51cto.com/iampomelo/1668963,如需转载请自行联系原作者
你可能感兴趣的文章
55.Azure内容分发网络(CDN)
查看>>
MySQL常见错误代码(error code)及代码说明
查看>>
微软MVP社区巡讲
查看>>
总结一下,MariaDB 10(MySQL5.6企业版分支)的主要新特性
查看>>
MS UC 2013-0-虚拟机-标准化-部署-2-模板机-制作-3-安装-Tool
查看>>
IDS与IPS的区别
查看>>
初试Windows 8 RTM
查看>>
Linux 下rpm包搭建LAMP环境
查看>>
Windows Server 2016-Nano Server介绍
查看>>
未来架构师的平台战略范例(4)_大数据
查看>>
Grizzly学习笔记(二)
查看>>
思科路由器动态VTI IPSec***配置
查看>>
***S启动时遇到1053错误
查看>>
CentOS7.5 使用 kubeadm 安装配置 Kubernetes1.12(四)
查看>>
shell脚本实现对系统的自动分区
查看>>
Tokyo Tyrant基本规范(5)--教程
查看>>
理解图形化执行计划 -- 第3部分:分析执行计划
查看>>
90后美女的全能测试蜕变之路
查看>>
audit.rules
查看>>
Windows 10企业批量部署实战之WDS配置
查看>>