Bird
0
0

Which of the following is the correct way to declare a standalone directive in Angular?

easy📝 Syntax Q12 of 15
Angular - Standalone Components
Which of the following is the correct way to declare a standalone directive in Angular?
A@Directive({ selector: '[appHighlight]' })
B@Directive({ selector: '[appHighlight]', standalone: false })
C@Directive({ selector: 'appHighlight', standalone: true })
D@Directive({ selector: '[appHighlight]', standalone: true })
Step-by-Step Solution
Solution:
  1. Step 1: Check selector syntax

    For attribute directives, the selector must be in square brackets, e.g., '[appHighlight]'.
  2. Step 2: Verify standalone flag

    To make a directive standalone, standalone: true must be set in the decorator.
  3. Final Answer:

    @Directive({ selector: '[appHighlight]', standalone: true }) -> Option D
  4. Quick Check:

    Standalone directive needs selector with [] and standalone: true [OK]
Quick Trick: Standalone directives need standalone: true and correct selector [OK]
Common Mistakes:
  • Missing square brackets in selector for attribute directive
  • Setting standalone to false or omitting it
  • Using element selector instead of attribute selector

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes