我正在使用HTML直接显示dialog
<!-- Dialog -->
<div class="modal fade" id="exampleModalCenter" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="exampleModalLongTitle">Something went wrong</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h5 class="modal-title" id="exampleModalLongTitle">Maximum 10 messages selected</h5>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Ok</button>
</div>
</div>
</div>
</div>
<button data-toggle="modal" data-target="#exampleModalCenter">RunIt</button>
但我想先做一些事情,所以我想通过javascript使用data-toggle="modal" data-target="#exampleModalCenter"
执行(click)
所以基本上这就是步骤:
1- (click)="test()"
通过data-toggle="modal" data-target="#exampleModalCenter"
test()
要获取包含它的DIV
,我尝试过:
test(){
var dialog= <HTMLDivElement>document.getElementById(exampleModalCenter);
}
但我找不到exampleModalCenter
答案 0 :(得分:0)
您应该使用attr.data-target
<button data-toggle="collapse"
[attr.data-target]="'#exampleModalCenter">RunIt
</button>
答案 1 :(得分:0)
首先,您必须添加点击方法&#39; test&#39;按钮。将模态的班级名称更改为&#39;模态淡出&#39;。之后,你的ts文件必须是这样的:
@ViewChild('exampleModalCenter') exampleModalCenter;
test() {
this.exampleModalCenter.nativeElement.className = 'modal fade show';
}