我有以下工厂:angularjs filterfilter为了通过在控制器/工厂
app.factory("ModuleFactory", function (api, $http, $q,filterFilter) {
var moduleList = [];
var categoryList = [];
var moduleTypeList = [];
var academyModuleTypeList = [];
var mostUsed = [];
var lastUpdated = null;
return {
/**
* @description This function gets the entire module list for the given users organization.
* @author Marc Rasmussen
* @returns {d.promise}
*/
getList: function() {
var d = $q.defer();
if (moduleList.length == 0) {
$http.get(api.getUrl('module', null))
.success(function (response) {
moduleList = response;
lastUpdated = new Date();
d.resolve(response);
});
}
else {
d.resolve(moduleList);
}
return d.promise;
},
getMostUsed: function() {
var d = $q.defer();
if(moduleList.length <= 0){
this.getList().then(function() {
})
}
}
}
});
现在列表moduleList
包含在这些对象objects
列表有一个场num_used
正如你可以看到我创建了一个名为getMostUsed
的函数,该函数需要返回moduleList,但是按字段num_used
desc
排序。
但是我不太清楚如何使用filterFilter
为此,我知道我可以只使用array.sort()
但是如果可能的话,我希望使用angular
函数吗?
任何人都可以指向正确的方向吗?
什么是filterFilter?您定义的过滤器的名称? – toskv