【问题标题】:ngx-bootstrap modal remove body scrollngx-bootstrap 模态删除正文滚动
【发布时间】:2018-05-07 11:33:36
【问题描述】:
modalRef: BsModalRef;
config = {
  animated: true,
  class: 'forgot-modal'
};
openModal(template: TemplateRef<any>) {
    this.modalRef = this.modalService.show(template, this.config);
}
closeModal() {
    this.modalRef.hide();
    this.modalRef = null;
}

上面的代码打开了我的模态。但是身体有一个需要移除的卷轴。我以某种方式发现,当打开模式时,modal-open 类没有附加到正文标记。

【问题讨论】:

    标签: angular ngx-bootstrap ngx-bootstrap-modal


    【解决方案1】:

    试试这个解决方法,你需要在你的组件中注入 Renderer2。

    modalRef: BsModalRef;
    config = {
      animated: true,
      class: 'forgot-modal'
    };
    openModal(template: TemplateRef<any>) {
       const onShown: Subscription = this.modalService.onShow.subscribe(() => {      
       setTimeout(() => {
        renderer.addClass(document.body, 'modal-open')
       }, 100);
       onShown.unsubscribe();
       const onHidden: Subscription = this.modalService.onHidden.subscribe(() => {
        renderer.removeClass(document.body, 'modal-open');
        onHidden.unsubscribe();
       });
      });
      this.modalRef = this.modalService.show(template, this.config);
    }
    closeModal() {
        this.modalRef.hide();
        this.modalRef = null;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-15
      • 2015-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-23
      相关资源
      最近更新 更多