Skip to content

Instantly share code, notes, and snippets.

@niallobrien
Created June 23, 2014 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niallobrien/293f174845fc04d89fc0 to your computer and use it in GitHub Desktop.
Save niallobrien/293f174845fc04d89fc0 to your computer and use it in GitHub Desktop.
.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