Bird
0
0

Which of the following is the correct syntax to declare a standalone component in Angular?

easy📝 Syntax Q12 of 15
Angular - Standalone Components
Which of the following is the correct syntax to declare a standalone component in Angular?
A@Component({ selector: 'app-test', standalone: true, template: '<p>Test</p>' }) export class TestComponent {}
B@Component({ selector: 'app-test', standalone: false, template: '<p>Test</p>' }) export class TestComponent {}
C@Component({ selector: 'app-test', standalone: true, templateUrl: 'test.html' }) export class TestComponent {} NgModule({ declarations: [TestComponent] })
D@Component({ selector: 'app-test', standalone: true }) export class TestComponent { template: '<p>Test</p>' }
Step-by-Step Solution
Solution:
  1. Step 1: Check the standalone property usage

    The standalone property must be set to true inside the @Component decorator.
  2. Step 2: Verify template declaration and class export

    The template can be inline with template or external with templateUrl. The class must be exported properly.
  3. Final Answer:

    @Component({ selector: 'app-test', standalone: true, template: '<p>Test</p>' }) export class TestComponent {} -> Option A
  4. Quick Check:

    Standalone true inside @Component with inline template [OK]
Quick Trick: Standalone true must be inside @Component decorator [OK]
Common Mistakes:
  • Setting standalone to false
  • Declaring template outside the decorator
  • Mixing NgModule declaration with standalone component

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes