当打开两个模态时如何更改ngx引导程序背景模态

问题描述 投票:1回答:1

enter image description here ngx-bootstrap对于带有bootstrap 4版本的Angular,当您打开一个弹出窗口时,您会看到以下代码,当从第一个模式中打开另一个弹出窗口(模式)时,背景工作正常,背景不透明度不会在第一个模式中反映出来弹出。当打开第二个模态时,不透明度不会改变如何更改第一个模态的不透明度(背景)。

import { Component, TemplateRef } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';

@Component({
  selector: 'demo-modal-service-nested',
  templateUrl: './service-nested.html'
})
export class DemoModalServiceNestedComponent {
  modalRef: BsModalRef;
  modalRef2: BsModalRef;
  constructor(private modalService: BsModalService) {}

  openModal(template: TemplateRef<any>) {
    this.modalRef = this.modalService.show(template, { class: 'modal-lg' });
  }
  openModal2(template: TemplateRef<any>) {
    this.modalRef2 = this.modalService.show(template, { class: 'second' });
  }
  closeFirstModal() {
    this.modalRef.hide();
    this.modalRef = null;
  }
}
<button type="button" class="btn btn-primary" (click)="openModal(template)">Open first modal</button>

<ng-template #template>
  <div class="modal-header">
    <h4 class="modal-title pull-left">First modal</h4>
    <button type="button" class="close pull-right" aria-label="Close" (click)="modalRef.hide()">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body">
    This is a first modal
    <button type="button" class="btn btn-primary" (click)="openModal2(templateNested)">Open second modal</button>
  </div>
</ng-template>

<ng-template #templateNested>
  <div class="modal-header">
    <h4 class="modal-title pull-left">Second modal</h4>
    <button type="button" class="close pull-right" aria-label="Close" (click)="modalRef2.hide()">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body">
    This is nested modal.<br>
    <button *ngIf="modalRef" type="button" class="btn btn-danger" (click)="closeFirstModal()">Close first modal</button>
  </div>
</ng-template>
angular5 bootstrap-modal ngx-bootstrap
1个回答
0
投票
我需要显示2个重叠模态,第二个比第一个小,我只是无法隐藏第一个。我的解决方案是将背景色应用于第二个:

openModal2(template: TemplateRef<any>) { this.modalRef2 = this.modalService.show(template, { class: 'second' }); document.getElementsByClassName('second')[0].parentElement.style.backgroundColor = 'rgba(0, 0, 0, 0.4)'; }

document.getElementsByClassName('second')[0] .parentElement.style.backgroundColor='rgba(0,0,0,0.4)';
© www.soinside.com 2019 - 2024. All rights reserved.