Bird
0
0

What is wrong with this standalone component code?

medium📝 Debug Q14 of 15
Angular - Standalone Components
What is wrong with this standalone component code?
@Component({ selector: 'app-error', standalone: true, template: `

Error component

` }) export class ErrorComponent {}
@Component({ selector: 'app-root', standalone: true, template: ``, imports: [ErrorComponent] }) export class AppComponent {}
AStandalone components cannot have templates.
BAppComponent does not import ErrorComponent in its imports array.
CThe selector 'app-error' is invalid for standalone components.
DErrorComponent should not be standalone if used inside another component.
Step-by-Step Solution
Solution:
  1. Step 1: Check component imports for nested usage

    AppComponent uses <app-error> but does not import ErrorComponent in its imports array.
  2. Step 2: Understand standalone component import rules

    Standalone components must import other standalone components they use in templates.
  3. Final Answer:

    AppComponent does not import ErrorComponent in its imports array. -> Option B
  4. Quick Check:

    Missing import of nested standalone component causes error [OK]
Quick Trick: Always import standalone components you use inside templates [OK]
Common Mistakes:
  • Thinking standalone components don't need imports
  • Believing selectors are restricted for standalone
  • Assuming standalone components can't have templates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes