1
import { Component, TemplateRef } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { BsModalRef } from 'ngx-bootstrap/modal/modal-options.class';

@Component({
  selector: 'demo-modal-service-static',
  templateUrl: './service-template.html'
})
export class DemoModalServiceStaticComponent {
  public modalRef: BsModalRef;
  constructor(private modalService: BsModalService) {}

  public openModal(template: TemplateRef<any>) {
    this.modalRef = this.modalService.show(template);
  }
}

创建模板模态

<template #template>
  <div class="modal-header">
    <h4 class="modal-title pull-left">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 modal.
  </div>
</template>

http://valor-software.com/ngx-bootstrap/#/modals#directive-section

嗨,如上所示,使用模板创建模式将在模板被隐藏时破坏模板。然而; 我不想被隐藏。那是因为,我使用模式从列表中多次选择某些属性。因此,每次,我都必须加载模态。这会导致性能问题。因此,有没有办法阻止它从 dom 中删除模态。

4

0 回答 0