Objective
I believe we all know the use of filters: one is in the use of HTML, one is in the JS code in the use of the following we have an example of in-depth understanding.
Instance Code
<! DOCTYPE html>
<html>
<head>
<meta charset = "UTF-8">
<title> Filter </ title>
<script src = "day2 / src / angular.js"> </ script>
<style type = "text / css">
</ style>
</ head>
<body>
<div ng-app = "fristApp">
<div ng-controller = "fristController">
<!-Used between multiple filters | Link->
<!-The essence of the parameter is to add the parameter in front of the number (used at the currency symbol)->
{{money | currency}} <br />
{{money | currency: '¥'}} <br />
{{str | uppercase}} <br />
{{json | json}} <br />
<!-Will be rounded up->
{{num | number: 3}} <br />
<!-Time Only MM is capitalized->
{{currenttime | date: 'yyyy-MM-dd-hh'}}
<!-Cutting of string->
{{strr | limitTo: 3}}
{{strr | limitTo: -3}}
<!-Sort by person's age->
<ul>
<li ng-repeat = "person in arr | orderBy: 'age': false">
{{person.name}}
</ li>
</ ul>
<!-true is located in the second position, where num cannot be added with "", the above addition of "" is because name is one of his attributes->
<ul>
<li ng-repeat = "n in [2,43,432,453,65] | orderBy: num: true">
{{n}}
</ li>
</ ul>
<!-Filter according to the attributes of person->
<input type = "text" ng-model = "name" />
<ul>
<li ng-repeat = "person in arr | filter: {'name': name}">
{{person.name}}
</ li>
</ ul>
</ div>
</ div>
</ body>
<script type = "text / javascript">
var myApp = angular.module ('fristApp', []);
myApp.controller ('fristController', function ($ scope, $ filter) {
$ scope.money = 100;
$ scope.str = "fsHIOiiiiIU";
$ scope.json = {name: "zhangsan", age: 40};
$ scope.num = 12432432432;
var time = new Date ();
$ scope.currenttime = time.getTime ();
$ scope.strr = "fujichao";
$ scope.arr = [
{name: 'zhangsan', age: 33},
{name: 'zhangsan2', age: 30},
{name: 'zhangsan3', age: 44},
{name: 'zhangsan4', age: 3}
];
// If the elements of the array are equal, the memory addresses of the two elements are the same.
var arrnum = [12,12,33,44];
if (arrnum [0] === arrnum [1]) {
console.log ("fji")
};
/ * Use filters in JS * /
// $ filter (the name of the filter) (object, condition)
var val = $ filter ('currency') ($ scope.money, '¥');
console.log (val);
var string1 = "fssdHIUHIjiojjOIJIOJ"
var valStr = $ filter ('uppercase') (string1);
console.log (valStr)
})
</ script>
</ html>
The Operation effect chart is as follows
Summarize
The above is the entire content of this article, I hope that the study or work to bring some help, if you have questions you can message exchange.