Best practice for calling the NgbModal open method

前端 未结 2 1180
野性不改
野性不改 2021-01-08 00:36

Toying around with the NgbModal and want to trigger the open method -> open(content: string | TemplateRef, options: NgbModalOptions) <- from somew

2条回答
  •  感情败类
    2021-01-08 01:29

    You can now do the following...

    Lets say you have a model component Confirm model that you want to use it in any other component.

    1. ModelComponentName is added to the declarations and entryComponent sections in the module.ts
    2. Dont forget to add NgbModule.forRoot() in the imports of your module file which contains the declarations you mentioned above.
    3. Ensure that your model component template is inside div tag and not the ng-template tag.

    You can then use the following open method from any other component.

    modalReference: NgbModalRef;
    constructor(private modalService: NgbModal) { }
    this.modalReference = this.modalService.open(ModelComponentName, {backdrop: 'static',size: 'lg', keyboard: false, centered: true});
    

提交回复
热议问题