Bird
0
0

You want to create a standalone Angular component that uses another standalone component called ButtonComponent. How should you declare the imports array in your component decorator?

hard📝 Application Q15 of 15
Angular - Standalone Components
You want to create a standalone Angular component that uses another standalone component called ButtonComponent. How should you declare the imports array in your component decorator?
A@Component({ standalone: true, imports: [ButtonComponent], template: '<app-button></app-button>' })
B@Component({ standalone: true, imports: ['ButtonComponent'], template: '<app-button></app-button>' })
C@Component({ standalone: true, imports: [NgModule], template: '<app-button></app-button>' })
D@Component({ standalone: true, template: '<app-button></app-button>' })
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to use other standalone components

    Standalone components can import other standalone components by listing them in the imports array.
  2. Step 2: Correct syntax for imports array

    The imports array must contain the component class itself, not a string or NgModule.
  3. Final Answer:

    @Component({ standalone: true, imports: [ButtonComponent], template: '<app-button></app-button>' }) -> Option A
  4. Quick Check:

    Imports array includes component classes, not strings [OK]
Quick Trick: Import component classes directly, not strings or modules [OK]
Common Mistakes:
  • Using string names instead of component classes in imports
  • Importing NgModule instead of component
  • Omitting imports array when using other standalone components

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes