Angular | How to set value of a signal based on the value of another signal?

Discussão em 'Angular' iniciado por guacamole, Dezembro 5, 2024.

  1. guacamole

    guacamole Guest

    I have two signals:

    isFoo = this.store.selectSignal(abcd);
    isBar = signal(false);


    isBar gets updated based on some other user interactions in the component. If the value of isFoo is true, isBar should always be false.

    In the component's constructor, I am using an effect to handle that like so:

    effect(() => {
    if (this.Foo())
    this.isBar.set(false)
    },
    {allowSignalWrites: true})


    Is there any other way to update the signal without having to use {allowSignalWrites: true} ? According to the documentation, that config option should be sparingly used. However, I am not sure how else to handle this scenario.

    Continue reading...

Compartilhe esta Página