Bird
0
0

How do you correctly define a standalone component in Angular?

easy📝 Syntax Q3 of 15
Angular - Standalone Components
How do you correctly define a standalone component in Angular?
A@Component({ standalone: false, selector: 'app-example', template: '<p>Example works!</p>' }) export class ExampleComponent {}
B@Component({ selector: 'app-example', template: '<p>Example works!</p>' }) export class ExampleComponent {}
C@NgModule({ declarations: [ExampleComponent] }) export class ExampleModule {}
D@Component({ standalone: true, selector: 'app-example', template: '<p>Example works!</p>' }) export class ExampleComponent {}
Step-by-Step Solution
Solution:
  1. Step 1: Identify standalone component syntax

    Standalone components require the property standalone: true in the @Component decorator.
  2. Step 2: Check the options

    @Component({ standalone: true, selector: 'app-example', template: '

    Example works!

    ' }) export class ExampleComponent {} correctly includes standalone: true along with selector and template.
  3. Final Answer:

    @Component({ standalone: true, selector: 'app-example', template: '

    Example works!

    ' }) export class ExampleComponent {}
    is the correct way to declare a standalone component.
  4. Quick Check:

    Standalone components must have standalone: true [OK]
Quick Trick: Standalone components need 'standalone: true' in @Component [OK]
Common Mistakes:
  • Omitting 'standalone: true' when declaring a standalone component
  • Confusing NgModule declarations with standalone component syntax
  • Setting 'standalone' to false or missing it entirely

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes