Created
June 23, 2014 22:56
-
-
Save niallobrien/293f174845fc04d89fc0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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