Why is my signal not updating the UI when using `++` or `--` operation

Discussão em 'Angular' iniciado por Naren Murali, Fevereiro 6, 2025.

  1. Naren Murali

    Naren Murali Guest

    I have this scenario, where I want to increment/decrement two values, so I use the standard ++ and -- operation to do this inside the update method of signals.

    import { Component, signal } from '@angular/core';
    import { bootstrapApplication } from '@angular/platform-browser';

    @Component({
    selector: 'app-root',
    template: `
    <hr/>
    {{id()}}
    <hr/>
    {{num()}}
    `,
    })
    export class App {
    id = signal(1);
    num = signal(1000);

    ngOnInit() {
    setInterval(() => {
    this.id.update((prev: number) => prev++);
    this.num.update((prev: number) => prev--);
    }, 2000);
    }
    }
    bootstrapApplication(App);


    Why are my signals updated, when I clearly incremented them.

    Stackblitz Replication

    Continue reading...

Compartilhe esta Página