2

I am trying to configure the current user inside the config part of my angular.js app and am getting the following error:

Error: Unknown provider: $resource from manyminds

This is how I am passing resource in:

myApp.config(function($routeProvider, $resource) {

I include the resource file before I include the app.js

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular-resource.js"></script>
<script src="assets/js/app.js"></script>

I don't get that error when passing $resource into any of my controllers - only when passing it into config. Can I not use $resource in config?

1 Answer 1

3

From the AngularJS documentation on Modules ("Module Loading & Dependencies" section):

Configuration blocks - get executed during the provider registrations and configuration phase. Only providers and constants can be injected into configuration blocks. This is to prevent accidental instantiation of services before they have been fully configured.

So, for example, you could inject $routeProvider into a config block, but not $route.

If you need information to be available to a controller before a route changes, you may consider using the resolve key of $routeProvider.when; if you assign a function to resolve, Angular will ensure the function is injected (just like a controller) when it runs the function; if you assign a string Angular will find the injectable of the same name and inject that.

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

Comments

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.