Bird
0
0

This Angular component code has an error:

medium📝 Debug Q14 of 15
Angular - Fundamentals
This Angular component code has an error:
@Component({
  selector: 'app-sample',
  template: `

{{title}}

` }) export class SampleComponent { title: string; constructor() { this.title = 'Hello'; } }

What is the error and how to fix it?
AMissing standalone: true; add it to @Component decorator
Btitle is not initialized; set default value in declaration
CNo error; code is correct as is
DTemplate syntax is wrong; use [title] instead of {{title}}
Step-by-Step Solution
Solution:
  1. Step 1: Check component decorator for standalone usage

    Modern Angular encourages standalone components for simplicity, but it's optional.
  2. Step 2: Verify code correctness

    The code initializes title in constructor and uses correct template syntax.
  3. Step 3: Confirm no error present

    No error exists; code is valid Angular component.
  4. Final Answer:

    No error; code is correct as is -> Option C
  5. Quick Check:

    Component works without standalone flag [OK]
Quick Trick: Standalone flag is optional; code initializes title correctly [OK]
Common Mistakes:
  • Thinking template syntax is incorrect
  • Assuming title must be initialized at declaration
  • Believing standalone flag is always required

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes