Bird
0
0

Identify the error in this Angular component code using input signals:

medium📝 Debug Q14 of 15
Angular - Signals
Identify the error in this Angular component code using input signals:
export class SampleComponent {
  @Input() data = signal();

  ngOnInit() {
    this.data.set('Hello');
  }
}
AInput signals must be readonly
BMissing initial value for signal()
CngOnInit() is not allowed in standalone components
DCannot call set() on input signals
Step-by-Step Solution
Solution:
  1. Step 1: Check signal initialization

    The signal data is declared without an initial value, which is invalid.
  2. Step 2: Understand signal requirements

    Signals must have an initial value when created, so signal() without arguments causes an error.
  3. Final Answer:

    Missing initial value for signal() -> Option B
  4. Quick Check:

    Signals need initial values [OK]
Quick Trick: Always initialize signals with a value [OK]
Common Mistakes:
  • Leaving signals uninitialized
  • Thinking set() is disallowed on inputs
  • Confusing lifecycle hooks usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes