When trying to post a URL with Angular 7 to the server, I encountered an error stating "blocked by CORS policy," although it worked fine in Angular 1.6.
The issue is related to CORS policy blocking access to XMLHttpRequest. The response to preflight request does not pass the access control check because it does not have an HTTP OK status.
return this.http.post<Driver>(url, this.emailAttributeObject, {
headers : new HttpHeaders({
'Content-type' : 'application/json'
})
})
.pipe(
catchError(this.handleError('driverDetails', driverDetails))
);
component file:
this.myDataService.sendEmail(this.driverDetails, this.initialValue)
.subscribe((response : Driver) => {
//this.driverDetails = response;
}, error =>
this.toastr.error(error.message,"Problem to send Email")
)
service file:
return this.http.post<Driver>(url, this.emailAttributeObject, {
headers : new HttpHeaders({
'Content-type' : 'application/json'
})
})
.pipe(
catchError(this.handleError('driverDetails', driverDetails))
);