The config function

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 11 years ago
Updated 6 years ago

This episode explains the config phase of an AngularJS application and how is it special in regards to $routeProvider (routing configuration) and providers in general.

John Lindquist: I want to take a second to talk about the "config function" and "providers" without going into too much detail because we will create our own providers later.

We are going to be using the "route providers" quite extensively so let's dive into it. If I try and inject the route provider into my app controller and see if I reload this, it will say, "unknown provider, provider, provider." Meaning that it is looking for a provider with the word "provider" on the end. This is actually unavailable, because it is looking for a service being created by a provider.

What that means is, what you actually do is you inject the route in here and it's going to find the route so no error. It's going to find the route because it found a provider.

Now if I were to try to inject route in here, I see an unknown provider route.

So at this point, in this phase, if your application is configuring it, all you have are these providers, which are the factories which generate an instance of things like "route," is the service that comes from the route provider.

At this point, when you are configuring your app, you are basically saying, "When I generate route, this is how I want it to appear." If you were to try for instance, you can actually access all the stuff you see in here from the route itself. So you could say, "a route routes." Access it like this, then try and paste in this guy. That's totally the gist.

It's just that if I do that, I am going to see a "Run Fine." So no errors were thrown. But what's going on is, this is way too late in the process because we need to reference the app controller so it can be initiated when you navigate to this URL. It has no idea that when you navigate to that URL that it wants to [inaudible 02:03] app controller.

Now you are going to see that its way too late. We can't find any controller and the services are not expected to do anything because the configuration needs to happen before you inject it into anything you want to use it in.

Just a quick review, again, these providers are available in the config function. You can generate your own, we'll talk about that later. But in the config function, we're going to be injecting a provider which will then...When you try to access the instance of it like a route, inside the controller then you can get things. A pre-configured instance based on what you do to configure it in here.

That's the basics of "provider" and we are going to dive a lot more into route provider here next.

egghead
egghead

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today