2

This is my code:

import { NgbModal } from '@ng-bootstrap/ng-bootstrap';` constructor(private http: Http, private route: ActivatedRoute,private router: Router, private modalService: NgbModal) { } editDocumentRow = function (documentId, modal) { this.http.get(ConstantComponent.url + '/documentmanagerapi/Get/' + documentId).map((res: Response) => res.json()).subscribe(data => { this.documentsRowDetails = data this.modalService.open(modal) this.modalService.close() // not working }) } 

I am trying to use this.modalService.close() in a different function. But it's not even working in the same function where this.modalService.open(modal) is working perfectly.

I am getting this error: this.modalService.close is not a function

Any suggestion what went wrong here?

1
  • 2
    modalService.close() will not work instead use this.activeModal.dismiss() Commented Sep 15, 2017 at 12:16

2 Answers 2

9

you can get the reference of the model open as the promise and close it.

editDocumentRow = function (documentId, modal) { this.http .get(ConstantComponent.url + "/documentmanagerapi/Get/" + documentId) .map((res: Response) => res.json()) .subscribe((data) => { this.documentsRowDetails = data; this.modalService.open(modal); this.modalReference = this.modalService.open(modal); this.modalReference.result.then( (result) => { this.closeResult = `Closed with: ${result}`; }, (reason) => { this.closeResult = `Dismissed ${this.getDismissReason(reason)}`; } ); }); }; 

Now you can close the model

this.modalReference.close(); 
Sign up to request clarification or add additional context in comments.

Comments

0

Open the modal :

constructor( private modalService: NgbModal ) { } this.modalService.open() 

Close Activate Modal :

constructor( public activeModal: NgbActiveModal ) { } editDocumentRow = function (documentId, modal) { this.activeModal.dismiss(); }) 

2 Comments

I am getting this error : Error: No provider for NgbActiveModal!
I have added this import { NgbModal,NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; but it doesn't seem to help. Please suggest

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.