Computed signals express values derived from other signals. Angular tracks the signals read during computation, allowing dependencies to follow executed branches.
Before you start
You should understand a component’s class, template and dependencies. Follow both the framework lifecycle and the ownership of each value or resource. Apply examples inside an Angular application; the surrounding application configuration and imports depend on the feature being demonstrated.
The practical goal is to reason through this situation: A computed total reads quantities and prices; changing either invalidates that derived result. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.
Step-by-step walkthrough
Step 1: Identify editable sources
Keep the collection and filter writable. The matching count depends on both rather than representing a third independent input.
Step 2: Derive the result
Use computed and read both signals inside it. Dependencies follow the reads actually executed during calculation.
Step 3: Avoid synchronization copies
Do not use an Effect to copy the count into another writable signal; that creates additional ordering and consistency concerns.
Worked scenario
A computed total reads quantities and prices; changing either invalidates that derived result.
const items = signal(['Angular', 'React']);
const query = signal('a');
const count = computed(() => items().filter(item =>
item.toLowerCase().includes(query().toLowerCase())
).length);Import signal and computed from @angular/core. Count starts at two, becomes one for query ‘ang’, and reflects collection replacements without a separate setter.
Common mistake
Copying derived values into writable signals creates synchronization obligations.
Verify the behavior
Change the query and collection independently. Verify each invalidates the result and that consumers never need to update count manually.
Interview exercise
Calculate a filtered item count.
Answer and reasoning
Derive it with computed from the filter and collection, avoiding an Effect that copies the count into separate state.
Continue learning
Compare the scenario with the Angular interview questions and test your understanding with the Angular MCQs. For terminology and implementation details, consult the reference material.