Complete the code to import the HttpClient module needed for GET requests.
import { HttpClientModule } from '@angular/common/http'; @NgModule({ imports: [[1]] }) export class AppModule {}
You need to import HttpClientModule to use Angular's HTTP client for GET requests.
Complete the code to inject HttpClient into the constructor for making GET requests.
import { HttpClient } from '@angular/common/http'; export class DataService { constructor(private [1]: HttpClient) {} }
The variable name for the injected HttpClient is usually httpClient or similar. It must be a valid identifier.
Fix the error in the GET request method to correctly call HttpClient's get function.
getData() {
return this.httpClient.[1]('https://api.example.com/data');
}The correct method to make a GET request with HttpClient is get.
Fill both blanks to subscribe to the GET request and log the response.
this.httpClient.get('https://api.example.com/data').[1](response => { console.[2](response); });
Use subscribe to listen to the Observable returned by get, and console.log to print the response.
Fill all three blanks to create a GET request with typed response and handle errors.
this.httpClient.get<[1]>('https://api.example.com/data').subscribe({ next: data => this.data = data, error: err => this.[2] = err.message, complete: () => console.[3]('Request complete') });
Use any as a generic type if no specific type is defined. Store error message in errorMessage and log completion with console.log.