Is there anyone who can assist me with why I am encountering an error in my Angular code while trying to use HttpHeaders to read the response status from the backend? Here is the specific error message: https://i.sstatic.net/tQu5t.jpg
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { map } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class CrudService {
// Base API URL
public url = 'http://localhost:8080/';
headerProperty: string;
constructor(private http: HttpClient) { }
createUser(data) {
return this.http.post(this.url + 'todo', data);
}
createAddress(data) {
return this.http.post(this.url + 'address', data);
}
loginStudent(data) {
const postHttpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
}),
observe: 'response' as 'body'
};
return this.http.post('http://localhost:8080/' + 'login', data,
postHttpOptions)
.pipe(map(response => {
return response;
}));
}
}
I have made modifications to the code by adding 'as body' into it, but now a new issue has arisen with my component.
saveStudentDetails(values) {
const studentData = new FormData();
studentData.append('id', values.id);
studentData.append('password', values.password);
this.crudService.loginStudent(studentData).subscribe(result => {
if (result.headers.status === '202') {
this.router.navigate(['address']);
alert('"success"');
return;
}
});
}
The error states that the property 'headers' does not exist on type 'object'.