I would like to use Ng Bootstrap Modal with a child component as the modal body. I'm not sure how I would achieve this...
export class ParentComponent {
@ViewChild("modal") private engineModal: TemplateRef<any>;
dialog: NgbModalRef | null;
constructor(private modalService: NgbModal) {}
openModal(): void {
this.dialog = this.modalService.open(this.engineModal);
}
cancelModal (): void {
if ( this.dialog ) {
this.dialog.dismiss();
this.dialog = null;
}
}
}
and, I know this is wrong, but ultimately I'd like to do something like this,
<ng-template #modal>
<app-child-component></app-child-component>
</ng-template>
Child component has a lot of Input and Output variables, so what whould be the best approach here?
You can project the content by passing it as a input property
Your modal component should have the below
modal-body
with the below input property
Update 1 : To change the values of
@Input()
property in the parent can be done as below,LIVE DEMO