Daimz
Daimz

Reputation: 3281

Close ng-Bootstrap Modal on save

How can I close the ng-bootstrap modal once my save function has been successful?

Here's what I have so far:

save(form, activeModal) {
    this.goalsService.createNewGoal(this.team_id, form.value, this.date_created, this.date_modified)
      .subscribe(
        () => {
          form.reset();

          activeModal.dismiss('Successfully created Goal');

        },
        err => alert(`error creating goal ${err}`)
      );

  }

Upvotes: 1

Views: 1612

Answers (2)

Kapil Thakkar
Kapil Thakkar

Reputation: 870

At the time of opening modal using NgbModal service, it will return NgbModalRef instance.

Using returned instance we can close or dismiss modal.

loginModel : NgbModalRef;
constructor(private modalService:NgbModal) {}

onOpen(){
     this.loginModel =  this.modalService.open(content);
}

onSave(){
.
.
.
   (success)=>{
       this.loginModel.close();
   }
}

Upvotes: 2

Daimz
Daimz

Reputation: 3281

Turns out it was a very simple fix. All I needed to do was change activeModal.dismiss('Successfully created Goal'); to this.activeModal.dismiss('Successfully created Goal');

Upvotes: 0

Related Questions