Bird
0
0

What is wrong with this observable to signal conversion code?

medium📝 Debug Q7 of 15
Angular - Signals
What is wrong with this observable to signal conversion code?
import { signal } from '@angular/core';
import { interval } from 'rxjs';
const count = signal(0);
interval(1000).subscribe(value => count = value);
Asubscribe callback must return a value
BCannot assign directly to signal variable; must use set()
Csignal() cannot hold numbers
Dinterval does not emit values every second
Step-by-Step Solution
Solution:
  1. Step 1: Understand signal immutability

    Signals are immutable references; you cannot reassign the variable.
  2. Step 2: Correct way to update signal value

    Use count.set(value) inside subscribe callback to update signal value.
  3. Final Answer:

    Cannot assign directly to signal variable; must use set() -> Option B
  4. Quick Check:

    Signal update method = D [OK]
Quick Trick: Use set() to update signal value inside subscriptions [OK]
Common Mistakes:
  • Reassigning signal variable instead of calling set()
  • Misunderstanding signal mutability

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes