【发布时间】:2018-01-12 18:29:10
【问题描述】:
无法让 Bootstrap 4.0 modal 在 Angular 4 项目中工作。
模态在一个简单的静态 HTML 页面中效果很好:https://jsfiddle.net/Lq73nfkx/1/
<!-- MODAL -->
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" 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>
您可以在下面的屏幕截图中看到,按下显示 Modal 会导致 html 在多个位置发生更改,不仅在模型 HTML 本身内,而且还对文档的 <body> 元素进行了操作。
执行 HTML 操作的 Bootstrap JavaScript 似乎没有在 Angular 4 项目中触发,当我在项目中使用完全相同的代码时,HTML 根本没有改变。
还有其他方法可以让我将 Bootstrap 与 Angular 4 一起使用吗?或者我应该使用另一个不是 Bootstrap 的 Angular 4 模态解决方案?
【问题讨论】:
-
在 Angular 中使用 bootstrap 的最简单方法是使用 ng-bootstrap.github.io/#/home 之类的库(仍处于测试阶段),或者如果它不必是 bootstrap,您可以尝试使用 angular 的材料库 material.angular.io
标签: angular bootstrap-4