简体   繁体   English

Angular 8 ng-bootstrap 模式未加载 CSS 类

[英]Angular 8 ng-bootstrap modal not loading CSS classes

I npm install @ng-bootstrap/ng-bootstrap@5.3.1 in an Angular 8 project, When I open the modal using the modal service, the first try the modal will take time to open.我在 Angular 8 项目中安装了 npm @ng-bootstrap/ng-bootstrap@5.3.1,当我使用模态服务打开模态时,第一次尝试打开模态需要时间。 the second time the modal does not open.第二次模态不打开。 Looking at the devtool, the modal is open just doesn't have CSS classes set.查看开发工具,模式是打开的,只是没有设置 CSS 类。 I did import bootstrap to the styles.scss file @import "~bootstrap/scss/bootstrap.scss";我确实将引导程序导入到 styles.scss 文件@import "~bootstrap/scss/bootstrap.scss"; I tried using JavaScript to inject the CSS classes after open the model but didn't make any difference.打开 model 后,我尝试使用 JavaScript 注入 CSS 类,但没有任何区别。

   @ViewChild('modalContent', { static: false }) private modalContent: TemplateRef<any>;
   // .....some code here....

    public openNgbModal(): NgbModalRef {
      return this.modalService.open(this.modalContent, {
        size: 'lg',
        backdrop: 'static',
        keyboard: false,
        windowClass : 'modal-content'
      });
    }

See below:见下文:

在此处输入图像描述

The correct html should be the below:正确的 html 应该如下: 在此处输入图像描述

Try calling the modalService.open() without any options and see if it make any difference.尝试在没有任何选项的情况下调用 modalService.open() 并查看它是否有任何区别。

this.modalService.open(this.modalContent)

Im not proud of the answer but it did get the job done.我并不为答案感到自豪,但它确实完成了工作。 Used javascript to add the classes manual.使用 javascript 添加类手册。

   public openNgbModal(): NgbModalRef {
      return this.modalService.open(this.modalContent, {
        size: 'lg',
        backdrop: 'static',
        keyboard: false,
        windowClass : 'modal-content'
      });

      const modalBackdrop = document.getElementsByTagName('ngb-modal-backdrop');
      // check the class if exists
      modalBackdrop[0].className = 'modal-backdrop fade show';
      
      const modalWindow = document.getElementsByTagName('ngb-modal-window');
      // check the class if exists
      modalWindow[0].className = 'modal fade show d-block';
      modalWindow[0].setAttribute('aria-modal', 'true');
      modalWindow[0].children[0].className = 'modal-dialog modal-s';
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM