0

I set up the configuration for my main module in the following way:

angular.module('main').config(function($routeProvider, $locationProvider, ConfigProvider)
    {
        $routeProvider
            .when('/home',
            {
                templateUrl : ConfigProvider.path.views + '/page/home.html',
                controller : 'PageHomeCtrl',
                resolve : {
                    resolveHomeData : function(ResolveService) { return ResolveService.resolveHome() }
                }
            });

        $locationProvider.html5Mode(true);
    }
);

The ResolveService takes care of resolving the routes and at the moment is very simple:

angular.module('app.resolve').factory('ResolveService', function($q, UserService)
{
    return {
        resolveHome : function()
        {
            var deferred = $q.defer();

            UserService.find('me', function(data)
            {
                deferred.resolve(data);
            }, function(data, status)
            {
                deferred.reject(data);
            });

            return deferred.promise;
        }
    }
});

This instead is the PageHomeCtrl:

angular.module('app.ui.page.home').controller('PageHomeCtrl', function($q, $scope, UserService, resolveHomeData)
{

});

As you can see I'm injecting the resolveHomeData in it but I get the following error from AngularJS:

Unknown provider: resolveHomeDataProvider

Why is resolveHomeData not injected correctly into my controller?

I'm concatenating everything with a Gulp script and I'm including all AngularJS files in the following order:

  1. Modules definitions
  2. Modules configurations
  3. Providers
  4. Controllers
  5. Directives
  6. Filters
  7. Services

Edit:

This is the main module definition:

angular.module('main',
    [
        'ngRoute',
        'app.config',
        'app.resolve',
        'app.ui.page.index',
        'app.ui.page.home',
        'app.ui.modal.login'
    ]
)
0

1 Answer 1

1

EDIT: deleted my answer before due to your comment.

AngularJS thinks your resolveHomeData is a provider/service instead of the resolved data. This happens because the controller is also defined in the HTML by accident, thus having twice the declaration for the controller: once in the HTML, and once in the config.

Remove the HTML and it should work.

Sign up to request clarification or add additional context in comments.

7 Comments

app.resolve is already in the main module definition. I'm updating the question with the main module definition. Also I can't put the service inside a variable because i'm putting all my modules inside anonymous functions to avoid collisions.
In my case the service is injected into the resolve function and I can tell you that it's working because the service is sending requests to the server.
@siannone I see. Then for some reason Angular thinks your parameter is a provider/service instead of the resolved variable. I'll try to see why.
@siannone Ok got a thought: in the HTML are you also defining the ng-controller="PageHomeCtrl" by accident ?
@siannone Great! Remove it and it should work. I'll update my answer.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.