the problem may be using different modules, use same module or inject the 
myAppName module into Home.

will this solve 

Thanks
Selvakumar K

On Tuesday, January 12, 2016 at 6:53:01 PM UTC+5:30, sergio de mattia wrote:
>
>
> 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.

Reply via email to