-
-
Save flipjs/25a8a7f6780fa65a79e4 to your computer and use it in GitHub Desktop.
This file contains 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
angular.module('app', []) | |
.service('UserService', function($http, $q) { | |
this.users = [] | |
this.user = {} | |
function getData(obj, prop, id) { | |
var q = $q.defer() | |
var url = '/users/' | |
$http.get(url + id).success(function(response) { | |
obj[prop] = response | |
q.resolve() | |
}) | |
return q.promise | |
} | |
this.all = function() { | |
getData(this, 'users') | |
} | |
this.get = function(id) { | |
getData(this, 'user', id) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment