Bird
0
0

Given this app module snippet, what will happen when the app runs?

medium📝 Predict Output Q13 of 15
Angular - HTTP Client
Given this app module snippet, what will happen when the app runs?
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  bootstrap: [AppComponent]
})
export class AppModule {}
AThe app will fail to make HTTP requests because HttpClientModule is not imported in imports array
BThe app will work fine and make HTTP requests
CThe app will throw a syntax error on startup
DThe app will not compile because BrowserModule is missing
Step-by-Step Solution
Solution:
  1. Step 1: Check module imports array

    Although HttpClientModule is imported at the top, it is missing from the imports array in @NgModule.
  2. Step 2: Understand effect of missing HttpClientModule in imports

    Without adding it to imports, Angular won't provide the HttpClient service, so HTTP requests will fail at runtime.
  3. Final Answer:

    The app will fail to make HTTP requests because HttpClientModule is not imported in imports array -> Option A
  4. Quick Check:

    HttpClientModule must be in imports array [OK]
Quick Trick: Import module in imports array to enable its features [OK]
Common Mistakes:
MISTAKES
  • Importing module but forgetting to add to imports array
  • Assuming import statement alone enables module
  • Confusing declarations with imports

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes