Skip to content

Instantly share code, notes, and snippets.

@vinay13
Last active January 14, 2016 05:11
Show Gist options
  • Save vinay13/828e7a038eb25bc5344c to your computer and use it in GitHub Desktop.
Save vinay13/828e7a038eb25bc5344c to your computer and use it in GitHub Desktop.
http://www.jvandemo.com/how-to-resolve-angularjs-resources-with-ui-router/
.factory('UserService', function ($resource) {
var data = $resource('http://jsonplaceholder.typicode.com/users/:user', {user: '@user'}, {
update:{
method:'PUT'
}
});
return data;
});
Inside controller(UserService){
UserService.update({user: 1}, {name: 'Saimon', email: '[email protected]'});
}
angular.module('demo')
.config(['$stateProvider', function ($stateProvider) {
$stateProvider
.state("customers", {
url : "/customers",
templateUrl: 'customers.html',
resolve: {
// A string value resolves to a service
customersResource: 'customersResource',
// A function value resolves to the return
// value of the function
customers: function(customersResource){
return customersResource.query();
}
},
controller : 'customersCtrl'
});
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment