Bird
0
0

Identify the error in this code snippet migrating from NgModules:

medium📝 Debug Q14 of 15
Angular - Standalone Components
Identify the error in this code snippet migrating from NgModules:
import { bootstrapApplication } from '@angular/platform-browser';
import { Component } from '@angular/core';

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

Welcome

` }) export class AppComponent {} bootstrapApplication(AppComponent, { providers: [] });
AbootstrapApplication requires bootstrapModule instead
BMissing imports array for dependencies in @Component
CStandalone components cannot have providers
DSelector 'app-root' is invalid for standalone components
Step-by-Step Solution
Solution:
  1. Step 1: Check standalone component dependencies

    If the component uses other modules or components, they must be listed in the imports array inside @Component.
  2. Step 2: Analyze given code

    The component has no imports array. The template uses *ngIf, which requires CommonModule in imports.
  3. Final Answer:

    Missing imports array for dependencies in @Component -> Option B
  4. Quick Check:

    Standalone components need imports: [CommonModule] for directives like *ngIf [OK]
Quick Trick: Standalone components need imports for dependencies [OK]
Common Mistakes:
  • Thinking bootstrapApplication needs bootstrapModule
  • Believing providers are disallowed in standalone
  • Assuming selector rules changed for standalone

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes