I am working in angular 4 using web api 2 my post call is not working doesn't hit api. The problem is that it doesn't even give me a single error. Here is my code
registerUser() {
this.confirmPasswordMessage = false;
if (this.registerForm.valid) {
this.confirmPasswordMessage = false;
if (this._registerModel.Password.trim() !== this._registerModel.ConfirmPassword.trim()) {
this.confirmPasswordMessage = true;
this._progressBar.done();
return false;
}
const _data = JSON.stringify(this._registerModel);
this._apiService.postCall('Account/Register', _data).subscribe(resp => {
}, error => () => {
console.log(error); }, () => {
});
} else {
return false;
}
}
Here is my api service code.
public postCall<T>(apiUrl: any, itemName: any): Observable<T> {
const _options = { headers: new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + localStorage.getItem('access_token')
}
)};
return this.http.post<T>(this.actionUrl + apiUrl, itemName, _options);
}
Here is my json I am passing. When i run this json through postman it hit the api. But I don't why it is not hitting it from angular application.
"{"FirstName":"Kamran","LastName":"Khan","Email":"[email protected]","UserName":"kamrankhan","Password":"Kamran@786","ConfirmPassword":"Kamran@786"}"
There is nothing wrong with the api it is working fine I tested using postman.
registerUsermethod gets called at all, if it does - is the form actually valid? (Btw, you also seem to redundantly reset the message this.confirmPasswordMessage)JSON.stringify()and also mention'Content-Type': 'application/json'? The data should be sent without the conversion:this._apiService.postCall('Account/Register', this._registerModel).