Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Angular HTTP client module.
Angular
import { HttpClientModule } from '@angular/common/http'; @NgModule({ imports: [[1]] }) export class AppModule {}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using HttpClient instead of HttpClientModule in imports.
Trying to import HttpModule which is deprecated.
✗ Incorrect
You need to import HttpClientModule in your Angular module to use HTTP services.
2fill in blank
mediumComplete the code to inject HttpClient into the constructor.
Angular
constructor(private [1]: HttpClient) {} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase names for injected variables.
Using the class name instead of a variable name.
✗ Incorrect
The injected variable name should be a lowercase descriptive name like http.
3fill in blank
hardFix the error in the POST request method call.
Angular
this.http.[1]('https://api.example.com/data', payload).subscribe(response => { console.log(response); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using get instead of post for sending data.
Using put or delete which have different purposes.
✗ Incorrect
To send data to the server, use the post method of HttpClient.
4fill in blank
hardFill both blanks to add headers and handle the POST request.
Angular
const headers = new HttpHeaders().set('[1]', '[2]'); this.http.post('https://api.example.com/data', payload, { headers }).subscribe();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing authorization header with content type.
Using wrong header values.
✗ Incorrect
Set the Content-Type header to application/json to tell the server the data format.
5fill in blank
hardFill all three blanks to create a POST request with typed response and error handling.
Angular
this.http.post<[1]>('https://api.example.com/data', payload).subscribe({ next: (data) => console.log(data.[2]), error: (err) => console.error('Error:', [3]) });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not specifying the generic type.
Accessing wrong property names.
Logging the whole error object instead of the message.
✗ Incorrect
Specify the expected response type User, access the name property, and log the error message.