Skip to content

Instantly share code, notes, and snippets.

@s9tpepper
Created April 9, 2012 06:31
Show Gist options
  • Save s9tpepper/2341949 to your computer and use it in GitHub Desktop.
Save s9tpepper/2341949 to your computer and use it in GitHub Desktop.
AngularJS Services
// In AngularJS 0.9.19
// Dont do...
angular.service("CustomServiceOne", function($resource) {
return $resource("/path/to/api/:aParam", {}, {
getSomething: {method: "GET", params: {aParam: 0}, isArray: false}
});
});
// Instead do this...
(function() {
CustomServiceOne.$inject = ["$resource"];
function CustomServiceOne($resource) {
return $resource("/path/to/api/:aParam", {}, {
getSomething: {method: "GET", params: {aParam: 0}, isArray: false}
});
}
angular.service("CustomServiceOne", CustomServiceOne);
})();
// Then you can use this .js file in any AMD module with something like RequireJS
// and then the optimizer will minify the services correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment