Country or region and language

    Choose your country or region and your language.

    Suggested for you

      All countries and regions

        Choose your character

        It shows in the top bar and on your profile. Change it any time.

        Angular signals: stored and derived state

        A signal holds a value that Angular can track when it is read. Use a writable signal for state you change and computed for a value derived from that state. Read both by calling them.

        Checked 22 November 2026

        A computed total

        Keep quantity and unit price as the inputs. Derive the total so neither input change leaves a stale value behind:

        import {signal, computed} from '@angular/core';
        
        const quantity = signal(0);
        const unitPrice = signal(12);
        const total = computed(() => quantity() * unitPrice());
        
        quantity.update(value => value + 3);
        console.log(total()); // 36
        unitPrice.set(15);
        console.log(total()); // 45

        set replaces the value. update calculates its replacement from the current value. computed is read-only, so total.set(45) is a type error. In a component template, {{ total() }} reads the value; omitting the call refers to the signal function.

        Dependencies and equality

        A computed value tracks signals read while its calculation runs. A branch that doesn’t read a signal doesn’t depend on it for that calculation. Test both branches when a display switches between a fixed value and a calculated value.

        Signals use referential equality by default. Mutating an array in place doesn’t create a new array reference. To add a row, return a new array with rows.update(current => [...current, newRow]). A read-only signal prevents writes through its signal API; it doesn’t freeze objects inside the value.

        Effects and Observable streams

        Use computed to express a derived value. An effect suits a side effect such as updating a nonreactive API, rather than keeping a second writable copy of the same total in sync. For asynchronous streams, Angular still works with RxJS. toSignal subscribes to an Observable and exposes its latest value as a signal; supply an initial value when the stream doesn’t emit synchronously.

        Create that bridge once and reuse it.

        Recreating it repeatedly can create repeated subscriptions.

        A signal practice task

        Add a discount signal to the example. A discount of 0 must preserve the total; changing quantity, price or discount must update the result. Then clear a list rendered from a signal and confirm its empty state appears. The Angular exercises give further cases. Return to the Angular course for checked component work, or rehearse the explanation with the interview questions.

        Sources

        Your Work Gym account

        Save your progress and pick up on another device. Your browser's progress comes with you.

        New accounts get 12 hours of full access: every course, unit, project and exam. The clock starts when you open your first lesson.

        Plan your practice from a job ad or syllabus

        Have a referral code?

        or

        You can keep practicing without an account.

        Help and feedback

        Ask a question, tell us what is not working, or share an idea. We reply by email.

        What is it about?

        We use it only to reply to you.