Last active
August 29, 2015 14:15
-
-
Save jraff/e554a1517c85fcc51273 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
function UserFactory($http) { | |
init(); | |
var users = {}; | |
var factory = { | |
getUsers: getUsers, | |
getUser: getUser | |
}; | |
return factory; | |
////////////// | |
function init() { | |
$http.get('http://localhost:3000/users') | |
.success(function(data) { | |
angular.forEach(data, function(item, index) { | |
users[data.id] = data; | |
}); | |
}) | |
.error(function(error, status) { | |
alert(error); | |
}); | |
} | |
function getUsers() { | |
return users; | |
}; | |
function getUser(id) { | |
return users[id]; | |
} | |
} | |
angular.module('User').factory('UserFactory', UserFactory); |
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('User').config(['$routeProvider', | |
function($routeProvider) { | |
$routeProvider. | |
when('/users', { | |
templateUrl: 'partials/users/list.html', | |
controller: 'UserListController' | |
}) | |
.when('/users/:id', { | |
templateUrl: 'partials/users/show.html', | |
controller: 'UserShowController' | |
}) | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment