Skip to content

Instantly share code, notes, and snippets.

@eladcandroid
Created October 29, 2025 08:39
Show Gist options
  • Save eladcandroid/72c6215d12e8222d4b84e0f4ef088404 to your computer and use it in GitHub Desktop.
Save eladcandroid/72c6215d12e8222d4b84e0f4ef088404 to your computer and use it in GitHub Desktop.
Angular Signals - Computed "bug"
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