我有以下工廠: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