E
E
enchikiben2016-04-03 19:43:05
Angular
enchikiben, 2016-04-03 19:43:05

How to organize an application in AngularJS?

Good afternoon!
Tell me how to do the following correctly, the application has a user, it is obtained from the server, how to make it so that when the controller is called, in the absence of this user (for some reason he did not have time to boot from the server), he would not allow the controller to execute and load the user's service to receive data and then loaded the called controller further? Tell me how and where to call.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Kondaurov, 2016-04-03
@kondaurov

If you use ui-router then the user can be routed through resolve in the state.

{
name: "index",
controller(user) { console.log(user)}
resolve: {
user: function (usersService) { return usersService.getUser()}
}
}

The controller will not be called if there are rejected promises in resolve

_
_ _, 2016-04-04
@AMar4enko

The power of ui-router is in hierarchical states. Before activating the app.level1.level2 nested state, the resolve sections of both the app and level1 parent states will be processed.
You make a top-level state, write resolve for general data in it, and inherit all other states from it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question