Bird
0
0

Find the error in this standalone component code:

medium📝 Debug Q7 of 15
Angular - Standalone Components
Find the error in this standalone component code:
@Component({
  selector: 'app-demo',
  standalone: true,
  template: `

Demo works!

`, imports: [CommonModule] }) export class DemoComponent {}
ACommonModule cannot be imported in standalone components.
BCommonModule must be imported from '@angular/common'.
Cimports array is not allowed in standalone components.
DNo error; this is a correct standalone component declaration.
Step-by-Step Solution
Solution:
  1. Step 1: Check CommonModule import

    CommonModule must be imported from '@angular/common' before usage.
  2. Step 2: Analyze given code

    The code snippet does not show the import statement for CommonModule, which causes an error.
  3. Final Answer:

    CommonModule must be imported from '@angular/common'. -> Option B
  4. Quick Check:

    Missing import statement causes error = CommonModule must be imported from '@angular/common'. [OK]
Quick Trick: Always import CommonModule from '@angular/common' before use [OK]
Common Mistakes:
  • Assuming CommonModule is globally available
  • Thinking imports array is disallowed
  • Ignoring missing import statements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes