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({ selector: 'app-example', standalone: false, template: '<p>Example</p>' }) export class ExampleComponent {}
B@Component({ selector: 'app-example', standalone: true, template: '<p>Example</p>' }) export class ExampleComponent {}
C@Component({ selector: 'app-example', template: '<p>Example</p>' }) export class ExampleComponent {}
D@NgModule({ declarations: [ExampleComponent], standalone: true }) export class ExampleModule {}
Step-by-Step Solution
Solution:
  1. Step 1: Use @Component decorator

    The component must be decorated with @Component.
  2. Step 2: Set standalone to true

    Adding standalone: true in the decorator makes it a standalone component.
  3. Step 3: Provide template or templateUrl

    The component must have a template or templateUrl defined.
  4. Final Answer:

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

    Example

    ' }) export class ExampleComponent {}
    correctly declares a standalone component.
  5. Quick Check:

    Standalone components require standalone: true in @Component [OK]
Quick Trick: Standalone components need 'standalone: true' in @Component [OK]
Common Mistakes:
  • Omitting 'standalone: true' in the component decorator
  • Trying to declare standalone components inside @NgModule
  • Setting standalone to false or missing it

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes