mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-11 13:23:02 -05:00
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:
22
apps/angular/52-lazy-load-component/src/app/app.component.ts
Normal file
22
apps/angular/52-lazy-load-component/src/app/app.component.ts
Normal 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);
|
||||
}
|
||||
12
apps/angular/52-lazy-load-component/src/app/app.module.ts
Normal file
12
apps/angular/52-lazy-load-component/src/app/app.module.ts
Normal 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 {}
|
||||
@@ -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 {}
|
||||
17
apps/angular/52-lazy-load-component/src/app/top.component.ts
Normal file
17
apps/angular/52-lazy-load-component/src/app/top.component.ts
Normal 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 {}
|
||||
BIN
apps/angular/52-lazy-load-component/src/favicon.ico
Normal file
BIN
apps/angular/52-lazy-load-component/src/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
13
apps/angular/52-lazy-load-component/src/index.html
Normal file
13
apps/angular/52-lazy-load-component/src/index.html
Normal 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>
|
||||
6
apps/angular/52-lazy-load-component/src/main.ts
Normal file
6
apps/angular/52-lazy-load-component/src/main.ts
Normal 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));
|
||||
5
apps/angular/52-lazy-load-component/src/styles.scss
Normal file
5
apps/angular/52-lazy-load-component/src/styles.scss
Normal 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 */
|
||||
2
apps/angular/52-lazy-load-component/src/test-setup.ts
Normal file
2
apps/angular/52-lazy-load-component/src/test-setup.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import 'jest-preset-angular/setup-jest';
|
||||
Reference in New Issue
Block a user