Skip to content

Commit bf6d885

Browse files
committed
feat(challenge 52): lazy-load-component
1 parent 0d15a0b commit bf6d885

5 files changed

Lines changed: 13 additions & 28 deletions

File tree

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
import { Component, signal } from '@angular/core';
1+
import { Component } from '@angular/core';
2+
import { PlaceholderComponent } from './placeholder.component';
3+
import { TopComponent } from './top.component';
24

35
@Component({
46
selector: 'app-root',
7+
imports: [TopComponent, PlaceholderComponent],
8+
59
template: `
610
<div class="h-screen bg-gray-500">
7-
@if (topLoaded()) {
11+
@defer (on interaction(loadComponent)) {
812
<app-top />
9-
} @else {
13+
} @placeholder {
1014
<app-placeholder />
1115
<button
12-
class="rounded-sm border border-blue-500 bg-blue-300 p-2"
13-
(click)="topLoaded.set(true)">
16+
#loadComponent
17+
class="rounded-sm border border-blue-500 bg-blue-300 p-2">
1418
Load Top
1519
</button>
1620
}
1721
</div>
1822
`,
19-
standalone: false,
2023
})
21-
export class AppComponent {
22-
topLoaded = signal(false);
23-
}
24+
export class AppComponent {}

apps/angular/52-lazy-load-component/src/app/app.module.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

apps/angular/52-lazy-load-component/src/app/placeholder.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ import { Component } from '@angular/core';
1313
height: 50%;
1414
}
1515
`,
16-
standalone: false,
1716
})
1817
export class PlaceholderComponent {}

apps/angular/52-lazy-load-component/src/app/top.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ import { Component } from '@angular/core';
1313
height: 50%;
1414
}
1515
`,
16-
standalone: false,
1716
})
1817
export class TopComponent {}
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
2-
import { AppModule } from './app/app.module';
1+
import { bootstrapApplication } from '@angular/platform-browser';
2+
import { AppComponent } from './app/app.component';
33

4-
platformBrowserDynamic()
5-
.bootstrapModule(AppModule)
6-
.catch((err) => console.error(err));
4+
bootstrapApplication(AppComponent).catch((err) => console.error(err));

0 commit comments

Comments
 (0)