Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to close the popup modal when we click on save or cancel button

I have an angular application, In that I have created the popover using angular.

.component.html

 <div class="form-group popover-form">
           
              <textarea class="form-control"  id="power" maxlength="1500" [(ngModel)]="name" name="name"></textarea>

          
            </div>
            <div>
              <button  class="btn btn-default cancel-btn">CANCEL</button>
              <button type="button" (click)="show = true" >SAVE</button>
            </div>
</div>
<p *ngIf="show">{{name}}</p>


So when I add some content in textarea and click on the save button I has to close the popup ,and also when we click on the cancel also It should close the popup.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Can anyone help on the same.

>Solution :

Assuming the show boolean flag is separate from the visible state of the popover then add a new boolean flag to your component ts which will be used to manage the visible state of the popover and toggle it with your cancel/save controls:

component ts:

showPopover = false

save() {
  this.show = true;
  this.showPopover = false;
}

component html:

<div class="form-group popover-form" *ngIf="showPopover">
    <textarea class="form-control" id="power" maxlength="1500" [(ngModel)]="name" name="name"></textarea>
</div>

<div>
    <button  class="btn btn-default cancel-btn" (click)="showPopover = false">CANCEL</button>
    <button type="button" (click)="save()">SAVE</button>
</div>

<p *ngIf="show">{{name}}</p>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading