ngx-bootstrap модальный удалить свиток тела - PullRequest
0 голосов
/ 07 мая 2018
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 не добавляется к тегу body при открытии модального окна.

1 Ответ

0 голосов
/ 04 сентября 2018

Попробуйте этот обходной путь, вам нужно добавить 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;
}
...