-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05-Filters.html
More file actions
155 lines (132 loc) · 4.18 KB
/
05-Filters.html
File metadata and controls
155 lines (132 loc) · 4.18 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>AngularJS - Filters</title>
<script src="js/lib/angular.min.js"></script>
</head>
<body ng-app="mainApp" ng-controller="studentController">
<div>
<h3>AngularJS - Filters</h3>
<p>Filters are used to change modify the data and can be clubbed in expression or directives using pipe character. Following is the list of commonly used filters.</p>
</div>
<table border="1">
<tbody>
<tr>
<th>Sr.No.</th>
<th>Name</th>
<th>Description</th>
</tr>
<tr>
<td>1</td>
<td>uppercase</td>
<td>converts a text to upper case text.</td>
</tr>
<tr>
<td>2</td>
<td>lowercase</td>
<td>converts a text to lower case text.</td>
</tr>
<tr>
<td>3</td>
<td>currency</td>
<td>formats text in a currency format.</td>
</tr>
<tr>
<td>4</td>
<td>filter</td>
<td>filter the array to a subset of it based on provided criteria.</td>
</tr>
<tr>
<td>5</td>
<td>orderby</td>
<td>orders the array based on provided criteria.</td>
</tr>
</tbody>
</table>
<h2>AngularJS Sample Application</h2>
<div ng-controller="studentController">
<table border="0">
<tr>
<td>Enter first name:</td>
<td>
<input type="text" ng-model="student.firstName">
</td>
</tr>
<tr>
<td>Enter last name: </td>
<td>
<input type="text" ng-model="student.lastName">
</td>
</tr>
<tr>
<td>Enter fees: </td>
<td>
<input type="text" ng-model="student.fees">
</td>
</tr>
<tr>
<td>Enter subject: </td>
<td>
<input type="text" ng-model="subjectName">
</td>
</tr>
</table>
<br/>
<table border="0">
<tr>
<td>Name in Upper Case: </td>
<td>{{student.fullName() | uppercase}}</td>
</tr>
<tr>
<td>Name in Lower Case: </td>
<td>{{student.fullName() | lowercase}}</td>
</tr>
<tr>
<td>fees: </td>
<td>{{student.fees | currency}}
</td>
</tr>
<tr>
<td>Subject:</td>
<td>
<ul>
<li ng-repeat="subject in student.subjects | filter: subjectName |orderBy:'marks'">
{{ subject.name + ', marks:' + subject.marks }}
</li>
</ul>
</td>
</tr>
</table>
</div>
<script>
var mainApp = angular.module("mainApp", []);
mainApp.controller('studentController', function($scope) {
$scope.student = {
firstName: "Mahesh",
lastName: "Parashar",
//fees: 500,
subjects: [{
name: 'Physics',
marks: 70
}, {
name: 'Chemistry',
marks: 80
}, {
name: 'Math',
marks: 65
}],
fullName: function() {
var studentObject;
studentObject = $scope.student;
return studentObject.firstName + " " + studentObject.lastName;
}
};
});
</script>
</body>
</html>