Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions apps/angular/52-lazy-load-component/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { Component, signal } from '@angular/core';
import { Component } from '@angular/core';
import { PlaceholderComponent } from './placeholder.component';
import { TopComponent } from './top.component';

@Component({
selector: 'app-root',
standalone: true,
imports: [TopComponent, PlaceholderComponent],
template: `
<div class="h-screen bg-gray-500">
@if (topLoaded()) {
@defer (on interaction(trigger)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2025-04-25 at 10 20 52 Even though i have the same solution i see all components loading in network tab, in this solution it will load in initial load. clicking button will not load it in another chunk

<app-top />
} @else {
} @placeholder {
<app-placeholder />
<button
class="rounded-sm border border-blue-500 bg-blue-300 p-2"
(click)="topLoaded.set(true)">
#trigger
class="rounded-sm border border-blue-500 bg-blue-300 p-2">
Load Top
</button>
}
</div>
`,
})
export class AppComponent {
topLoaded = signal(false);
}
export class AppComponent {}
12 changes: 0 additions & 12 deletions apps/angular/52-lazy-load-component/src/app/app.module.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Component } from '@angular/core';
template: `
I'm a placeholder component.
`,
standalone: true,
styles: `
:host {
display: grid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Component } from '@angular/core';
template: `
I am a very heavy, expensive component that should be lazy loaded.
`,
standalone: true,
styles: `
:host {
display: grid;
Expand Down
8 changes: 3 additions & 5 deletions apps/angular/52-lazy-load-component/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';

platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch((err) => console.error(err));
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Loading