0

I have a component, it's working fine until I didn't add an heavy children component that freeze the page. Now I would implement a lazy loading for the children component (is that the right solution?).

Also, I start to load the component only if "dataForMapReady" is true.

Actually, that's my html in fhater:

FATHER HTML

<div style="margin: 1.5em 1.5em;" [ngbCollapse]="isCollapsed">
  <div *ngIf="dataForMapReady">
    <mm-map-management [newsearch]="newsearch" [parameters]="parametersToMap" [resultsTotal]="results.total" [checkedFavorite]="checkedFavorite" [sortField]="sortField" [sortDir]="sortDir"></mm-map-management>
  </div>
</div>

I can't understand how to implement lazy loading in this case, I'm newbie of Angular.

1 Answer 1

1

Your applicatuion must be devided in modules to Implement Lazy-loading

In your routing module, you need to set routing for child compmenents something like

const routes: Routes = [
    {
        path: 'items',
        loadChildren: () => import('./items/items.module').then(m => m.ItemsModule)
    }
];

You can download sample App for lazy Loading implementation https://angular.io/generated/zips/lazy-loading-ngmodules/lazy-loading-ngmodules.zip

Configuring step-by-step lazy-loaded route https://angular.io/guide/lazy-loading-ngmodules

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

4 Comments

You can also check live example on Stackblitz. stackblitz.com/angular/…
Actually my app-routing.module.ts is like this: const routes: Routes = [ { path: "companies", component: AppCompanies}, can't use your tip above
It should be something like { path: "companies", loadChildren: () => import('./companies/companies.component').then(m => m.AppCompanies).then(MmMapManagementComponent) no?
In step 1 there should be separate module for companies and component In step 2 you need to load your companies component in companies module In step 3 you need to load your companies module in your main routing file For detailed working see stackblitz.com/angular/…

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.