Struggling with implementing a change password feature in Angular 7,
On the backend side, if the current password is incorrect, it will return true.
An error message should appear on the Angular side, but I'm encountering an issue where I have to click the submit button twice to show the error message. Even though I can see the response in logs printing true value, the *ngIf directive is not working as expected.
Template:
<span *ngIf="hasError">
Wrong current password value
</span>
Component:
hasError: boolean;
submit () {
this.apiService
.changePassword(this.formGroup.value).subscribe(res => {
console.log(res);
this.hasError = res; });
Service:
changePassword(body: any){
return this.http.post<any>(this.url + 'changePassword', body);
}
Could someone provide insight into why I need to click the submit button twice to display the HTML element?
Thank you