How / Whether to replace a getter with a paramater by a computed signal

Discussão em 'Angular' iniciado por monkey, Fevereiro 27, 2025.

  1. monkey

    monkey Guest

    Is there a comparable signals based approach to something like this:

    /** PROPS */

    selectedOption = signal<string | null>(null);

    getSelectedState(option: string): boolean | undefined {
    if (this.selectedOption() === null) {
    return undefined;
    }
    return option === this.selectedOption();
    }



    @for (option of list(); track option) {
    <monkey-chip
    [variant]="'frequency-sel'"
    [text]="option"
    [selected]="getSelectedState(option)"
    (click)="onSelect(option)"
    />
    }


    What's I'd like to achieve is a computed value to replace getSelectedState(option), but I can't think how this should work? Can we make this fully reactive, to the extent that zone.js could be removed and it would still work?

    I played around with computed, but as I understand it computed doesn't accept any arguments, so that isn't really any use.

    Continue reading...

Compartilhe esta Página