我正在尝试在使用 Angular CLI 构建的 Angular 应用程序中使用 Bootstrap4 工具提示。
Bootstrap4 alpha 文档说我需要运行此命令才能启用工具提示:
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
因此,我在 app.component.ts 中添加了一个 ngAfterViewInit() 函数来做到这一点:
ngAfterViewInit() {
$('[data-toggle="tooltip"]').tooltip();
}
在应用程序 html 文件中使用这个:
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="top" title="Hi there!">
Tooltip Test
</button>
将鼠标悬停在按钮上时,我确实看到了一个工具提示,但这只是一个普通的浏览器工具提示,而不是 Bootstrap4 工具提示。
在运行时,我收到错误:
ERROR ReferenceError: $ is not defined
将此行添加到组件没有帮助。
declare var $: any;
我已经仔细检查了 jquery、tether 和 boostrap js 文件是否按顺序包含在项目 angular-cli.json 文件的脚本部分中。
有什么建议我可以让它工作吗?
谢谢!