Hello Sergio,
That's simply because You must *name* your services/factories/etc., like
this:
myApp.service('loadHttpService', ['loadHttpService', '$window', '$http',
function (loadHttpService, $window, $http) {
// Your code here
});
Hope it helps.
El martes, 12 de enero de 2016, 10:23:01 (UTC-3), sergio de mattia escribió:
>
>
> 0down votefavorite
> <http://stackoverflow.com/questions/34743129/angularjs-unable-to-resolve-a-required-dependency-when-trying-to-use-a-global#>
>
> I am using a function which is used in more than 1 controller, so I
> thought to create a service and use it globally.
>
> That's why I included a file commonService.js in my index.html
>
> 'use strict';var myApp = angular.module('myAppName');
> myApp.service(['loadHttpService', '$window', '$http', function
> (loadHttpService, $window, $http) {
> this.loadHttpService = function (url) {
> ...
> };
> return $http.jsonp(url, {
> params: {
> callback: "JSON_CALLBACK"
> }
> })
> .then(function (response) {
> ...
> });
> };}]);
>
> and used it in my homeController, including the service as dependency, as
> below:
>
> 'use strict';
> angular.module('Home') .controller('HomeController', ['$scope', '$rootScope',
> '$http', '$window', '$state', 'loadHttpService',
> function ($scope, $rootScope, $http, $window, $state, loadHttpService) {
> ...
> var url = "http://xxx";
> loadHttpService.loadHttp(url);
>
> }]);
>
> But this is leading me to such error https://docs.angularjs.org/error/
> $injector/unpr?p0=loadHttpServiceProvider%20%3C-%20loadHttpService%20%3C-%20HomeController
>
> Why is it happening and how to fix it?
>
> Please note: myAppName is the name of my app (used in ng-app).
>
> I am very new to angularjs and feel free to add any tip to do it in a
> better way.
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.