如何使用 ng-modal 垂直居中模态对话框


是否可以

以某种方式指定以模态对话框为中心的类? 外部元素有一个 windowClass 选项,但我看不到以内部元素为中心的指定模式对话框的方法。

我刚刚开始使用 Angular,我知道它违反了它的原则,但我发现实现居中的唯一方法是在 HTML 模板中指定开瓶器功能,如下所示:

    <button (click)="openModal(myModalTemplateId)" btn btn-secondary">

并在组件中定义这个讨厌的函数,如下所示:

    openModal(content) {
      let x = this.modalService.open(content);
      // change the padding value for your case or use some other styling
      x._windowCmptRef._component._elRef.nativeElement.style = 'display: block; padding-top: 30%';
      // you can try to use the code bellow to set the class but it's not working for me
      // x._windowCmptRef._component._elRef.nativeElement.children[0].classList.add('modal-dialog-centered');
    }

最新更新