Skip to content
Open
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
14 changes: 6 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,26 +1,24 @@
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { PlaceholderComponent } from './placeholder.component';
import { TopComponent } from './top.component';

@Component({
selector: 'app-root',
template: `
<div class="h-screen bg-gray-500">
@if (topLoaded()) {
@defer (on interaction(button)) {
<app-top />
} @else {
} @placeholder {
<app-placeholder />
<button
class="rounded-sm border border-blue-500 bg-blue-300 p-2"
(click)="topLoaded.set(true)">
#button>
Load Top
</button>
}
</div>
`,
changeDetection: ChangeDetectionStrategy.Eager,
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [TopComponent, PlaceholderComponent],
})
export class AppComponent {
topLoaded = signal(false);
}
export class AppComponent {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';
template: `
I'm a placeholder component.
`,
changeDetection: ChangeDetectionStrategy.Eager,
changeDetection: ChangeDetectionStrategy.OnPush,
styles: `
:host {
display: grid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';
template: `
I am a very heavy, expensive component that should be lazy loaded.
`,
changeDetection: ChangeDetectionStrategy.Eager,
changeDetection: ChangeDetectionStrategy.OnPush,
styles: `
:host {
display: grid;
Expand Down
Loading