angular-ui / ui-router

The de-facto solution to flexible routing with nested views in AngularJS
http://ui-router.github.io/
MIT License
13.56k stars 3.01k forks source link

Update AngularJS lazy loading guide #3717

Closed ViieeS closed 4 years ago

ViieeS commented 5 years ago

This is a (check one box):

My version of UI-Router is: 1.0.18

Needs to update the lazy loading guide.

Current Behavior:

lazy loading - ui-router 2018-07-05 15-08-03

Expected Behavior:

AngularJS officially support lazy loading since v1.6.7:

angular js 2018-07-05 15-10-41

Documentation

Example:

New example based on the old one:

var futureState = {
    name: 'contacts.**',
    url: '/contacts',
    lazyLoad: function ($transition$) {
        var $q = $transition$.injector('$q');
        var $injector = $transition$.injector('$injector');
        var moduleName = "ContactsModule";

        return $q(function (resolve, reject) {
            $.getScript("./contacts.module.js", function () {
                resolve($injector.loadNewModules([moduleName]));
            });

        });
    }
};
jrencz commented 5 years ago

StateDeclaration.lazyLoad should return Promise<LazyLoadResult> but $injector.loadNewModules returns undefined

ViieeS commented 5 years ago

@jakebian yes, you're right. That's why we use $q service here.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

This does not mean that the issue is invalid. Valid issues may be reopened.

Thank you for your contributions.