ng-bootstrap and Angular 6: Can't resolve all parameters for NgbModalRef: (?,?,?,?)

我是研究僧i 提交于 2019-12-02 04:39:10

So the solution to this is not to use NgbModalRef but to use NgbActiveModal with the suggestions that the guys above have suggested.

Within the app.module.ts file you need to ensure that all components that contain a modal are within the entryComponents options and NgbModule.forRoot() in the imports options.

@NgModule({
    imports: [
        NgbModule.forRoot()
    ],
    entryComponents: [
        AccountManagementComponent, 
        CompetitionManagementComponent
    ]
})

Within the component you need to import NgbActiveModal

import {NgbModal, NgbActiveModal} from "@ng-bootstrap/ng-bootstrap";

and then create a variable

activeModal: NgbActiveModal;

Create a function that will act as your open()

open(content: any) {
    this.activeModal = this.modalService.open(content,{ ariaLabelledBy: "modal-basic-title", backdrop: "static", keyboard: false });
}

In our case we have a form in the modal so this needs to save and then if the save is successful it will close the modal and display a msg on the main page.

save(model: any): void {
        this.dbService.save(model).subscribe(
            data => {
                if (data.Successful === false) {
                    this.modelMsg = data.Information;
                } else {
                    this.msg = data.Information;
                    this.activeModal.close();
                }

            },
            error => this.msg = <any>error);
    } 

I hope this helps others that come across this issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!