fix: bug in effect move

This commit is contained in:
thomas
2024-05-15 14:43:11 +02:00
parent 60c9964a9e
commit e90419be13
15 changed files with 16 additions and 16 deletions

View 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!');
}
});
}
}

View File

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

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>signal-bug-in-effect</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 class="flex flex-col gap-5 p-10"></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 */