Working flawlessly in angular 11
Within the parent component
import { Component, OnInit, TemplateRef} from '@angular/core';
import { BsModalRef, ModalOptions, BsModalService } from 'ngx-bootstrap/modal';
import { ModalChildComponent } from '../../shared/modal-child/modal-child.component';
@Component({
selector: 'app-parent',
templateUrl: './parent.component.html',
styleUrls: ['./parent.component.css']
})
export class ParentComponent implements OnInit {
bsModalRef: BsModalRef;
constructor( private modalService: BsModalService
) {
this.openModalWithComponent();
}
ngOnInit(): void {
}
public openModalWithComponent() {
let initialState = { message: 'popup message', title:'popup title'};
let modalConfig = { animated: true, keyboard: true, backdrop: true, ignoreBackdropClick: false };
/* This demonstrates opening a Modal Component from another component */
this.bsModalRef = this.modalService.show(ModalCalendlyComponent,
Object.assign({}, modalConfig, {class: 'modal-sm', initialState
}));
}
}
Within the child component
import { Component, OnInit } from '@angular/core';
import { BsModalRef, ModalOptions, BsModalService } from 'ngx-bootstrap/modal';
@Component({
selector: 'app-modal-child',
templateUrl: './modal-child.component.html',
styleUrls: ['./modal-child.component.css']
})
export class ModalChildComponent implements OnInit {
constructor(
public bsModalRef: BsModalRef,
public options: ModalOptions
) {
console.log(this.options.initialState);
}
ngOnInit(): void {
}
}