L
L
LEKAPb2015-10-16 18:07:00
Angular
LEKAPb, 2015-10-16 18:07:00

Can AngularJS make a fully lazy application?

Good time of the day!
The task is to make a fully modular lazy application.
Now there is a bunch of Angular + RequireJS i.e. angular itself and an empty application start perfectly asynchronously with the dependencies specified in the RequireJS config file loaded. But the problem is that in angula.module("app") itself, you will need to immediately configure all state for all modules - which is very bad.
Next step:
After running the application, you need to contact the REST service or just a JSON file that will tell you which modules exist. And already with the loading of modules and their dependencies, work further.
The main problem is how to work with $stateProvider in this case, because I would like angular to be able to load states, controllers, directives, services for these modules when following links of the following type:
localhost/ReportsModule - Must load the state for this module :
.state('ReportsModule', {
url: '/ReportsModule',
templateUrl: '/ReportsModule/templates/index.html',
controller: 'ReportsMainController',
});
then load the ReportsMainController controller with its dependencies.
Is there such a possibility at all or is it possible to do only lazy controllers through requireJs?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-10-16
@LEKAPb

There is no such possibility, at least out of the box. Read the discussion in the official repository. In general, for most Angular projects, it's easier to just load everything once on the client and work with it.
Another option - if your application is correctly divided into directives (and not separate controllers with views), then you can try to make lazy loading of services in factories + lazy loading of directives. Purely theoretically, this is possible, and purely theoretically, this way you can lazily load most of the project.
ps it seems like they promised to do something with this in angular 1.5, but I didn't follow - for me it's unnecessary. In Angular2, this will be essentially available out of the box, since standard ES2015 modules are used as a module system.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question