How do I use an injected angular module's service in my app?
-
21-12-2019 - |
Pregunta
I'm venturing into injecting different angular modules into my app. One module I created contains a service that I would like to inject into a controller. Does anyone have a good explanation of how to do this?
My app.js:
angular.module('myApp', ['ngRoute', 'myModule']);
myModule which contains a service I want to inject:
angular.module('myModule')
.factory('coolService', ['$rootScope', function ($rootScope) {
return {
// API calls
}]);
An example of how to correctly inject 'coolService' into this controller would answer my question nicely:
angular.module('myApp')
.controller('myController', ['$scope', function ($scope) {
...
}]);
Solución
angular.module('myApp')
.controller('myController', ['$scope', 'coolService', function ($scope, coolService) {
coolService.do...
}]);
thats all...
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow