mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-13 14:23:02 -05:00
fix: bug in effect move
This commit is contained in:
53
apps/signal/50-bug-in-effect/src/app/app.component.ts
Normal file
53
apps/signal/50-bug-in-effect/src/app/app.component.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
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!');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user