Playing with NgbModal and you want to call the open method → open(content: string | TemplateRef<any>, options: NgbModalOptions) <- from another place, except for the template code. In my case, I want to pass the string as a parameter when the method is run in the .ts file of my component. When you start the method using the button in the html file like this: <button (click)="open(content)">Launch demo modal</button> , the code works fine, of course, with all the code from <template></template> to html file.
Trying to do something with this:
logoutScreenOptions: NgbModalOptions = { backdrop: 'static', keyboard: false }; lockedWindow: NgbModalRef; lockedScreenContent= ` <template #content let-c="close" let-d="dismiss"> <div class="modal-header" style="text-align: center"> <h3 class="modal-title">Title</h3> </div> <div class="modal-body"> <p>Body</p> </div> <div class="modal-footer"> <p>Footer</p> </div> </template> `; openLockedScreen(){ this.open(this.lockedScreenContent); } open(content) { console.log(content); this.lockedWindow = this.modalService.open(content, this.logoutScreenOptions); this.lockedWindow.result.then((result) => { this.closeResult = `Closed with: ${result}`; }, (reason) => { this.closeResult = `Dismissed ${this.getDismissReason(reason)}`; }); }
The code works without errors, and the modal opens like this: Modal without visualized content ... this is not quite what I want!
Also tried like this, with exactly the same result:
lockedScreenContent= ` <div class="modal-header" style="text-align: center"> <h3 class="modal-title">Title</h3> </div> <div class="modal-body"> <p>Body</p> </div> <div class="modal-footer"> <p>Footer</p> </div> `;
What am I missing? It would be impossible to simply pass the string as the parameter "content"?
It is impossible to see how to use the templateRef parameter from the ts file!
source share