过滤器:过滤器可以使用一个管道字符(|)添加到表达式和指令中。多个过滤器时也是用 (|) 隔开
Angualrjs 过滤器可以用于转换数据
currency:格式化数字为货币格式
filter;从数组项中选择一个子集:筛选
lowercase:格式化字符串我小写
uppercase :格式化字符串为大写
orderby :根据某个表达式排列数组
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>
orderby 过滤器根据表达式排列数组
<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>