AngularJS 在控制器或服务中使用过滤器
例子
通过注入$filter,Angular模块中任何定义的过滤器都可以用于控制器、服务、指令甚至其他过滤器。
angular.module("app")
.service("users", usersService)
.controller("UsersController", UsersController);
function usersService () {
this.getAll= function () {
return [{
id: 1,
username: "john"
}, {
id: 2,
username: "will"
}, {
id: 3,
username: "jack"
}];
};
}
function UsersController ($filter, users) {
var orderByFilter = $filter("orderBy");
this.users= orderByFilter(users.getAll(), "username");
//现在用户按他们的用户名排序:jack,john,will
this.users= orderByFilter(users.getAll(), "username", true);
//现在用户按他们的用户名排序,以相反的顺序:will,john,jack
}
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短