Created
April 9, 2012 06:31
-
-
Save s9tpepper/2341949 to your computer and use it in GitHub Desktop.
AngularJS Services
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
// 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