Search code examples
javascriptangulartypescriptangular-router

What is the benefit of providing a function to loadChildren?


In the article Understanding Modules and Services the author says:

if you organized your modules this way, you can still use the loadChildren keyword without actually Lazy Loading the module, as a proof that your module is independent and well-structured:

This is the code:

//Within contacs.module.ts
//Doesn't it need an export?
function contactsEntryPoint() {
    return ContactsModule();
}

//Within the app-routing.module.ts
{
    path: 'contacts',
    loadChildren: contactsEntryPoint
}

Does anyone understand what this is trying to illustrate?


Solution

  • This is setting up the code for lazy-loading; but the program actually eager-loads the module.

    The reason for doing so (as presented), is to ensure that you don't have any inter-module dependencies (especially singleton providers!).