過濾器:過濾器可使用一個管道字符(|)添加到表達式和指令中。多個過濾器時也是用 (|) 隔開數組
Angualrjs 過濾器能夠用於轉換數據app
currency:格式化數字爲貨幣格式spa
filter;從數組項中選擇一個子集:篩選code
lowercase:格式化字符串我小寫對象
uppercase :格式化字符串爲大寫blog
orderby :根據某個表達式排列數組ip
currency過濾器字符串
<div ng-app=
"
myApp
" ng-controller=
"
costCtrl
">
數量: <input type=
"
number
" ng-model=
"
quantity
">
價格: <input type=
"
number
" ng-model=
"
price
">
<p>總價 = {{ (quantity * price) | currency }}</p>
</div>
<script>
var app = angular.module(
'
myApp
', []);
app.controller(
'
costCtrl
', function($scope) {
$scope.quantity =
1;
$scope.price =
9.99;
});
</script> input
orderby 過濾器根據表達式排列數組it
<div ng-app="myApp" ng-controller="namesCtrl">
<p>循環對象:</p>
<ul>
<li ng-repeat=
"
x in names | orderBy:'country'
">
{{ x.name +
'
,
' + x.country }}
</li>
</ul>
</div>
<script src=
"
namesController.js
"></script>
filter過濾器 過濾輸入
按test表明的內容篩選,同時按orderby順序,同時改成大寫
<div ng-app=
"
myApp
" ng-controller=
"
namesCtrl
">
<p>輸入過濾:</p>
<p><input type=
"
text
" ng-model=
"
test
"></p>
<ul>
<li ng-repeat=
"
x in names | filter:test | orderBy:'country'
">
{{ (x.name | uppercase) +
'
,
' + x.country }}
</li>
</ul>
</div>
<script src=
"
namesController.js
"
></script>