I have the following factory:
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 () {
})
}
}
}
});
Now the list moduleList contains a list of objects in these objects there is a fieldnum_used
As you can see i have a created a function called getMostUsed this function needs to return the moduleList but ordered by the field num_used desc.
However i am not quite sure how to use filterFilter for this, i know that i could just use array.sort() however i wish to use the angular function for it if it is possible?
Can anyone point me in the right direction?