Bird
0
0

Identify the issue in this Angular standalone component setup:

medium📝 Debug Q6 of 15
Angular - Standalone Components
Identify the issue in this Angular standalone component setup:
@Component({ selector: 'sample-comp', standalone: true, template: '

Sample works

' }) export class SampleComponent {} @Component({ selector: 'app-root', standalone: true, template: '' }) export class AppComponent {}
ASampleComponent should not be standalone if used inside another component
BAppComponent does not import SampleComponent in its imports array
CAppComponent must declare SampleComponent in an NgModule
DThe selector 'sample-comp' is invalid for standalone components
Step-by-Step Solution
Solution:
  1. Step 1: Check component imports

    Standalone components used inside other standalone components must be imported.
  2. Step 2: Analyze given code

    AppComponent uses <sample-comp> but does not import SampleComponent.
  3. Step 3: Identify error

    Missing import causes Angular to not recognize SampleComponent.
  4. Final Answer:

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

    Always import standalone components you use [OK]
Quick Trick: Import standalone components before usage [OK]
Common Mistakes:
  • Assuming standalone components auto-import
  • Thinking NgModules are required for standalone components
  • Misunderstanding selector validity

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes