Bird
0
0

You have a signal holding an array of tasks:

hard📝 Application Q8 of 15
Angular - State Management
You have a signal holding an array of tasks:
const tasks = signal(['task1', 'task2']);

Which code correctly adds 'task3' to the tasks signal reactively?
Atasks.set([...tasks(), 'task3']);
Btasks.set(tasks.push('task3'));
Ctasks.update(tasks + 'task3');
Dtasks = [...tasks, 'task3'];
Step-by-Step Solution
Solution:
  1. Step 1: Understand signal value access

    Access the current array with tasks().
  2. Step 2: Create new array with added task

    Use spread operator to create a new array including 'task3'.
  3. Step 3: Update the signal

    Use tasks.set() with the new array to update reactively.
  4. Final Answer:

    tasks.set([...tasks(), 'task3']); -> Option A
  5. Quick Check:

    Update signals immutably by setting new values [OK]
Quick Trick: Use set() with new array copy to update signals [OK]
Common Mistakes:
  • Using push() which returns length, not array
  • Trying to update signal directly without set()
  • Concatenating array and string incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes