This video shows a more generalized way of using the AngularJS resolve feature with controllers to organize the conditions before the controller is instantiated. The video shows how to condition the controller's instantiation on more than one set of actions (function), and even pass values from the condition processing into the controller's scope once it gets instantiated.
John Lindquist: A vast majority of the time, you are using resolve, you are associating it also with a controller, so in this instance "app controller." One of the conventions you will see used is...People will create a variable like "app controller" and then they will attach the resolved property or the reference to that function here. Let's call it something simple like "load data."
So if we are to grab this and just drop it here, we are really not doing anything special. We are just organizing our code this way.
Now we have this pointing to app control load data. Let's just rename this to load data...That will make more sense because what we can do now is, if you have multiple things, you need to prepare before your controller is ready. Let's have this next one be "prep data." We'll just say "app control prep data," do the same thing here. I am just going to duplicate this entire thing and call this "prep data."
Now we can have these two things fire off and resolve your [inaudible 01:29] just work...After two seconds though, nothing is going to change there and you'll notice if we'll say...We will just log out load data and log out prep data.
This is not going to behave like a promise where one happens and the other happens, all this is going to happen at the same time. Once both of them are ready, then that's going to trigger the route change and everything.
One thing to note here is you can actually resolve things...you can pass things into resolve so instead of log in out load data, what I am going to do is [inaudible 02:15] or pass that, have that be what resolves from this. Same here, I will kind of get rid these counter log lines.
Then, we are going to inspect the route that comes into the controller. So if I just do counter log and log out the route, you can see that when I refresh here, it will log out the route and we can say well, the current route, route.current.locals, is going to have load data. Again, this is this property here is going to refer to this text load data, and then prep data which is a property here is going to resolve to prep data.
So you can see, you can actually access what gets resolved from these promises by looking at the locals on the route. I would for first [inaudible 03:16] on services or something but this is another way of accessing them. We will go into more detail in the future videos.