How can I make a direct call to RESTService.get
without using AngularJS’ dependency injection in the code snippet below?
angular.module('RESTModule', ['ngResource']).
factory('RESTService', ['$resource', function($resource) {
return $resource('http://jsonplaceholder.typicode.com/posts/1', {});
}
]);
I tried creating a library method as shown below, but it doesn't work as expected. Is there a way to achieve this functionality without relying on factory()
?
var MyLibrary = {};
MyLibrary.method = function() {
// ...
// The line below fails to execute successfully
angular.module('RESTModule').factory('RESTService').get();
};
Perhaps I am approaching this in the wrong way and should consider writing an AngularJS service instead. Any guidance or suggestions would be greatly appreciated.
Thank you!
Side note: I am currently developing an application that allows developers to include their own forms (views) and modules. Instead of requiring them to inject modules like RESTModule
, I would prefer they can simply call a predefined "static" library method like MyLibrary.method
.