Bird
0
0

You have a module-based Angular app but want to convert a component to standalone. Which error will you encounter if you forget to add imports for used Angular features like CommonModule?

medium📝 Debug Q14 of 15
Angular - Standalone Components
You have a module-based Angular app but want to convert a component to standalone. Which error will you encounter if you forget to add imports for used Angular features like CommonModule?
ATemplate errors like 'ngIf' is not a known property or directive.
BRuntime error: Cannot find module 'CommonModule'.
CNo errors, Angular auto-imports CommonModule.
DCompilation error: Component must be declared in a module.
Step-by-Step Solution
Solution:
  1. Step 1: Understand standalone component imports

    Standalone components must explicitly import Angular modules like CommonModule to use directives such as ngIf.
  2. Step 2: Identify error from missing imports

    If CommonModule is missing, Angular template compiler reports errors that directives like ngIf are unknown.
  3. Final Answer:

    Template errors like 'ngIf' is not a known property or directive. -> Option A
  4. Quick Check:

    Missing CommonModule import = template directive errors [OK]
Quick Trick: Standalone needs explicit imports for Angular directives [OK]
Common Mistakes:
  • Assuming Angular auto-imports CommonModule
  • Expecting runtime errors instead of template errors
  • Confusing module declaration errors with import errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes