2

This is my code:

myApp = angular.module("myApp", []);

myApp.config(['$routeProvider', '$controllerProvider', 
                       '$compileProvider', '$filterProvider',  
                       'routeResolver', myConfigFunction] );
angular.bootstrap(document, ['myApp']);    

Whenever I do this, I get the error: Unknown provider: routeResolver from myApp

If however I move the angular.bootstrap before the config function, ie:

myApp = angular.module("myApp", []);
angular.bootstrap(document, ['myApp']);    

myApp.config(['$routeProvider', '$controllerProvider', 
                       '$compileProvider', '$filterProvider',  
                       'routeResolver', myConfigFunction] );

Then I don't get any errors, but the config function myConfigFunction is not called. (The function just logs a line to console).

What am I doing wrong?

2
  • Do you use Chrome or IE? Commented Aug 4, 2013 at 20:37
  • @MaximShoustin Chrome Commented Aug 4, 2013 at 20:56

1 Answer 1

1

I am not sure what routeResolver actually is (might be this?)

Since only providers can be injected into the config() block you also need to add the word provider so routeResolver becomes routeResolverProvider and the error will go away.

myApp.config(['$routeProvider', '$controllerProvider', 
                       '$compileProvider', '$filterProvider',  
                       'routeResolverProvider', myConfigFunction] );

Working example on jsfiddle

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

8 Comments

Since only providers can be injected into the config() block this should be mentioned in the documentation somewhere...but thanks. Is this only the config block, or is it the same everywhere i.e in order for the dependency block to work, all services must have providers?
and you are correct, routeResolve is inspired by what that article said. :)
It is mentioned under the config section in the module documentation. docs.angularjs.org/guide/module
Not all services require providers, you can use providers when you want to make your service configurable.
This is still not working, I get the same error. Here's my code: jsfiddle.net/rMHME
|

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.