Additions/52 lazy load component (#963)

* feat: create challenge 52 on lazy load component

Initial boilerplate from `nx g @angular-challenges/cli:challenge`

* feat: revert to NgModule

Copy of 31

* feat: initial version of starting point

* feat: add documentation

* feat: pr tweaks

Add author file
Remove thomas from the contributor list
Add a more direct hint

* feat: pr tweaks

Update "Go to the latest Challenge" link
This commit is contained in:
Lance Finney
2024-05-27 10:27:15 -05:00
committed by GitHub
parent a07954fa73
commit c8ba057fe0
29 changed files with 397 additions and 20 deletions

View File

@@ -0,0 +1,22 @@
import { Component, signal } from '@angular/core';
@Component({
selector: 'app-root',
template: `
<div class="h-screen bg-gray-500">
@if (topLoaded()) {
<app-top />
} @else {
<app-placeholder />
<button
class="rounded-sm border border-blue-500 bg-blue-300 p-2"
(click)="topLoaded.set(true)">
Load Top
</button>
}
</div>
`,
})
export class AppComponent {
topLoaded = signal(false);
}

View File

@@ -0,0 +1,12 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { PlaceholderComponent } from './placeholder.component';
import { TopComponent } from './top.component';
@NgModule({
declarations: [AppComponent, PlaceholderComponent, TopComponent],
imports: [BrowserModule],
bootstrap: [AppComponent],
})
export class AppModule {}

View File

@@ -0,0 +1,17 @@
import { Component } from '@angular/core';
@Component({
selector: 'app-placeholder',
template: `
I'm a placeholder component.
`,
styles: `
:host {
display: grid;
padding: 20px;
background-color: #f0f0f0;
height: 50%;
}
`,
})
export class PlaceholderComponent {}

View File

@@ -0,0 +1,17 @@
import { Component } from '@angular/core';
@Component({
selector: 'app-top',
template: `
I am a very heavy, expensive component that should be lazy loaded.
`,
styles: `
:host {
display: grid;
padding: 20px;
background-color: #f0f0f0;
height: 50%;
}
`,
})
export class TopComponent {}

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>angular-lazy-load-component</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>
<app-root></app-root>
</body>
</html>

View File

@@ -0,0 +1,6 @@
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch((err) => console.error(err));

View File

@@ -0,0 +1,5 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
/* You can add global styles to this file, and also import other style files */

View File

@@ -0,0 +1,2 @@
import '@testing-library/jest-dom';
import 'jest-preset-angular/setup-jest';