我想删除页面上打开的模态,但我无法访问锁定文档的div元素
我无法访问这个div,无法定义一个ID或名称来通过Renderer2、删除它
<div class="modal-backdrop fade show"></div>
像这样的
this.renderer.removeChild(document.body, HTMLDivElement);
我认为删除它的最佳方法是使用*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(...
所在的位置。