Search code examples
angularngx-bootstrap

Unable to pass modal options and class in ngx-bootstrap modal


I'm using ngx-bootstrap modal

const modalRef = this.modalService.show<ListComponent>(ListComponent);
    modalRef.content.selecteduse.subscribe((x) => {
        this.func1();
    });

here i have modaloptions also

modOpt: ModalOptions = {
    backdrop: 'static', 
    keyboard: false,
    ariaLabelledBy: 'modal-basic-title',
    ignoreBackdropClick: true,
    id: 1,
 }

trying to add modOpt and class

 const modalRef = this.modalService.show<ListComponent>(ListComponent,{ class: 'modal-dialog create_modal_new', ...this.modOpt });

unable to add getting this error

Argument of type '{ id?: number; backdrop?: boolean | "static"; keyboard?: boolean; focus?: boolean; show?: boolean; ignoreBackdropClick?: boolean; class: string; animated?: boolean; initialState?: Partial; providers?: StaticProvider[]; ariaLabelledBy?: string; ariaDescribedby?: string; }' is not assignable to parameter of type 'ModalOptions'

Any solution Thanks


Solution

  • Could you try casting the type to ModalOptions to get rid of this error.

     const modalRef = this.modalService.show<ListComponent>(ListComponent,
        { class: 'modal-dialog create_modal_new', ...this.modOpt } as ModalOptions);
    

    If not, please share a stackblitz with the issue replicated.