feat(): challenge 58

This commit is contained in:
thomas
2025-03-08 13:01:08 +01:00
parent 49eca53c7f
commit ec0f415735
23 changed files with 324 additions and 17 deletions

View File

@@ -0,0 +1,22 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { CardComponent } from './card.component';
@Component({
imports: [CardComponent],
selector: 'app-root',
template: `
<app-card>
<div title>Card 1</div>
<div message>Message 1</div>
</app-card>
<app-card [small]="true">
<div title>Card 2</div>
<div message>Message 2</div>
</app-card>
`,
host: {
class: 'p-4 block flex flex-col gap-1',
},
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent {}

View File

@@ -0,0 +1,5 @@
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
export const appConfig: ApplicationConfig = {
providers: [provideZoneChangeDetection({ eventCoalescing: true })],
};

View File

@@ -0,0 +1,25 @@
import { ChangeDetectionStrategy, Component, input } from '@angular/core';
@Component({
selector: 'app-card',
template: `
@if (small()) {
<ng-content select="[title]" />
<ng-content select="[message]" />
} @else {
<div class="p-4">
<div class="text-2xl">
<ng-content select="[title]" />
</div>
<ng-content select="[message]" />
</div>
}
`,
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
class: 'p-4 border border-grey rounded-sm flex flex-col w-[200px]',
},
})
export class CardComponent {
small = input<boolean>(false);
}

View File

@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>angular-content-projection-condition</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,7 @@
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { appConfig } from './app/app.config';
bootstrapApplication(AppComponent, appConfig).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 */