Toying around with the NgbModal and want to trigger the open method -> open(content: string | TemplateRef<any>, options: NgbModalOptions)
<- from somewhere else than the template code. In my case case I want to pass a string as a parameter when running the method in the .ts file of my component. When running the method via a button in the html file like so: <button (click)="open(content)">Launch demo modal</button>
, the code works great, of course with all the code from within the <template></template>
in the html file.
Trying to accomplish 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)}`;
});
}
Code runs with no errors, and the modal opens like so: Modal without rendered content ...which is not exactly 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? Wouldn't it be possible to just pass a string as the "content" parameter?
Can't see to get my head around how to use a templateRef parameter from the ts file either!