【发布时间】:2017-10-21 22:26:03
【问题描述】:
我无法使用 Typescript 切换引导模式。我正在使用默认的引导程序 4 模态。这是代码。
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
这是 Bootstrap 4 提供的用于切换模态的按钮
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
我没有在我的应用程序中使用此按钮。我想通过我的一个 Angular 2 组件中的一个函数来展示 Modal。我已经使用以下代码访问了 html 元素。
ngOnInit() {
this.modalElement = document.getElementById('myModal');
}
现在我需要激活模式以使用方法调用来显示它。我不打算找到解决方案来做到这一点。我尝试了 .show() 和其他解决方案之类的方法,但都没有奏效。
【问题讨论】:
-
如果你不使用 ng-bootstrap,你需要 jQuery 依赖。 v4-alpha.getbootstrap.com/components/modal/#via-javascript 文档非常直接地介绍了如何打开模式。
标签: angular typescript2.0 twitter-bootstrap-4