1、uppercase,lowercase 大小寫轉換
{{ "lower cap string" | uppercase }} // 結果:LOWER CAP STRING {{ "TANK is GOOD" | lowercase }} // 結果:tank is good
2、date 格式化
{{1490161945000 | date:"yyyy-MM-dd HH:mm:ss"}} // 2017-03-22 13:52:25
3、number 格式化(保留小數)
{{149016.1945000 | number:2}}
4、currency貨幣格式化
{{ 250 | currency }} // 結果:$250.00 {{ 250 | currency:"RMB ¥ " }} // 結果:RMB ¥ 250.00
5、filter查找
輸入過濾器可以通過一個管道字符(|)和一個過濾器添加到指令中,該過濾器後跟一個冒號和一個模型名稱。
filter 過濾器從數組中選擇一個子集
// 查找name爲iphone的行 {{ [{"age": 20,"id": 10,"name": "iphone"}, {"age": 12,"id": 11,"name": "sunm xing"}, {"age": 44,"id": 12,"name": "test abc"} ] | filter:{'name':'iphone'} }}
<body ng-app="myApp" ng-controller="myCtrl"> <input type="text" ng-model="test"/> <div ng-repeat="x in arrs | filter:test">{{x.name}}</div> <script> var app = angular.module("myApp",[]); app.controller("myCtrl",function ($scope) { $scope.arrs = [ {name:1111}, {name:2222}, {name:3333} ]; }) </script> </body>
6、limitTo 截取
{{"1234567890" | limitTo :6}} // 從前面開始截取6位 {{"1234567890" | limitTo:-4}} // 從後面開始截取4位
7、orderBy 排序
// 根id降序排 <div class="" ng-repeat="v in city | orderBy:'-id' | filter : ''"> <p ng-bind="v.name" style="color:red;"></p> </div><!--orderBy 過濾器根據表達式排列數組 默認正序asc,倒序添加-負號--> // 根據id升序排 <div class="" ng-repeat="v in city | orderBy:'id'"> <p ng-bind="v.name"></p> </div><!--orderBy 過濾器根據表達式排列數組-->