I'm using ngx-bootstrap for modal in Angular 6, I have created one shared modal in which i want to add different Html templates in the modal-body section. How to add HTML template or How I can pass the dynamic components to the shared modal.
Shared modal component:
@Component({
selector: 'modal-content',
template: `
<div class="modal-header">
<h4 class="modal-title">{{headerText}}</h4>
</div>
<div *ngIf="showTemplate" class="modal-body">
<templateselector></templateselector>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" (click)="clickOk()">
{{actionButtonText}}</button>
</div>
`
})
export class ModalContentComponent{
headerText: string;
actionButtonText: string;
showTemplate: boolean;
templateselector: any;
constructor(public bsModalRef: BsModalRef) { }
clickOk() {
this.bsModalRef.hide();
}
Calling Component:
@Component({
selector: 'modal-content',
template: `
<div>
<button type="button" class="btn"
(click)="openModalWithComponent()">modal</button>
</div>`
})
export class DynamicComponent{
constructor(public bsModalRef: BsModalRef) { }
openModalWithComponent(message: string, title: string) {
const initialState = {
headerText: title,
actionButtonText: "Continue",
showTemplate: true,
templateSelector : NewComponent //From here i need to pass different
//HTML which should get load in Modal body.
};
this.bsModalRef = this.modalService.show(ModalContentComponent, {
initialState });
}
From calling component I should be able to pass the name of the component, I dont want to hardcode the selector as that components are going to change, and that component along with the modal header and footer should get loaded.