Files
angular-challenges/apps/signal/50-bug-in-effect/src/app/app.component.ts
2024-05-15 14:43:11 +02:00

54 lines
1.0 KiB
TypeScript

import {
ChangeDetectionStrategy,
Component,
effect,
model,
} from '@angular/core';
import { FormsModule } from '@angular/forms';
@Component({
standalone: true,
imports: [FormsModule],
selector: 'app-root',
template: `
<section class="flex gap-5">
<p>MacBook</p>
<p>1999,99 €</p>
</section>
<section>
<p>Extras:</p>
<div>
<input type="checkbox" [(ngModel)]="drive" />
+500 GB drive-space
</div>
<div>
<input type="checkbox" [(ngModel)]="ram" />
+4 GB RAM
</div>
<div>
<input type="checkbox" [(ngModel)]="gpu" />
Better GPU
</div>
</section>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent {
drive = model(false);
ram = model(false);
gpu = model(false);
constructor() {
/*
Explain for your junior team mate why this bug occurs ...
*/
effect(() => {
if (this.drive() || this.ram() || this.gpu()) {
alert('Price increased!');
}
});
}
}