Created
October 29, 2025 08:39
-
-
Save eladcandroid/72c6215d12e8222d4b84e0f4ef088404 to your computer and use it in GitHub Desktop.
Angular Signals - Computed "bug"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Component, computed, signal } from '@angular/core'; | |
| @Component({ | |
| selector: 'app-root', | |
| template: ` | |
| <h3>Counter value {{ counter() }}</h3> | |
| <h3>Derived counter: {{ derivedCounter() }}</h3> | |
| <button (click)="increment()">Increment</button> | |
| <button (click)="multiplier = 10">Set multiplier to 10</button> | |
| `, | |
| }) | |
| export class App { | |
| counter = signal(0); | |
| multiplier: number = 0; | |
| derivedCounter = computed(() => { | |
| if (this.multiplier < 10) { | |
| return 0; | |
| } else { | |
| return this.counter() * this.multiplier; | |
| } | |
| }); | |
| increment() { | |
| console.log(`Updating counter...`); | |
| this.counter.set(this.counter() + 1); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment