-1

I am new to Angular 6 development and I am looking for a solution for the following problem.

I tried to implement the following which loads with a condition (*ngIf = "showError")

<div *ngIf="showError" class="alert">
  <span class="closebtn" onclick="this.parentElement.style.display='none';">&times;</span> 
  <strong>Alert </strong> Error occured when saving data.
</div>

Once it shows in the 1st time when I close this div with a close button and then I proceed to generate the same error which means showError = true but from 2nd time onward I can't make this div visible due to this.parentElement.style.display='none'. How can I solve this to show this div each time showError = true even after closing the div before?

SiddAjmera
  • 38,129
  • 5
  • 72
  • 110

1 Answers1

3

You can simply do it by setting to false

<span class="closebtn" (click)="showError = false">&times;</span> 
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396