Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
.factory('StaffList', function ($http) {
var staffList = [];
return {
all: function () {
// returns promise object
return staffList = $http.get('API_URL', {
cache: true
});
},
get: function (staffId) {
// fetch the data first
if (staffList == '') {
staffList = this.all();
}
// TODO: refactor so it searches through staffList and not make another http call
staffList.success(function(response) {
for (i = 0; i < response.data.length; i++) {
if (staffId === response.data[i].entry_id) {
return response.data[i];
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.