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?
Hello yes you are right you have to use ViewChild to do this, then create an open function that use the open function as described :
See the .ts example https://ng-bootstrap.github.io/#/components/modal/examples
You simply have to do this, and you can now play with your modal
EDIT: To access your child component inside your ng-template : // bad way
=> I would personally encapsulate the ng-template inside the ModalInfoComponent, ModalNewsComponent html and use directly my answer ;)