如何从体内删除<div class =“ modal-backdrop fade show”> </div>?

时间:2019-08-25 19:24:49

标签: angular dom modal-dialog bootstrap-modal angular-renderer2

我想删除页面上打开的模式,但无法访问锁定文档的div元素,

我无法访问该div,无法定义ID或名称以通过Renderer2将其删除,

<div class="modal-backdrop fade show"></div>

类似的东西

this.renderer.removeChild(document.body, HTMLDivElement);

1 个答案:

答案 0 :(得分:1)

我相信删除它的最好方法是使用* ngIf。它添加和删除带条件的DOM元素。

例如

HTML

<div *ngIf="foo" class="modal-backdrop fade show">
  I will be added to the DOM only if foo is true
</div>

打字稿

someMethod(value){
  this.foo=value // or this.foo=!this.foo
}

其中someMethod()是您的this.renderer.removeChild(...所在的位置。