2

I am implementing lazy loading technique in an Angular6 project, but I am confused as for the syntax to fetch the "lazy" module.

Inside the app.module (main module), when declaring the Routes, I would like to ask if the following:

{ path: 'lazy', loadChildren: './lazy/lazy.module#LazyModule' }

is equivalent to the following:

import { LazyModule } from './lazy/lazy.module';

{ path: 'lazy', loadChildren: () => LazyModule }

Through my eyes, the second approach actually makes useless the lazy loading since the LazyModule has to already been imported in order to call it. In the first approach, I successfully call the LazyModule without having to import it.

Any help is welcome.

1 Answer 1

3

You're right, the second solution is actually not lazy loading. As you stated, the purpose of lazy loading is not to import the module (like on your first example), otherwise it is included in the initial chunk, thus eagerly loaded.

So the answer to your question is: no, the two syntaxes are not equivalent.

Sign up to request clarification or add additional context in comments.

2 Comments

although, I wish there was a way to avoid magic strings but anyway!
@GeorgeGeorge I know that feel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.