javascript - 正确处理 Angular 7+ 中的新“Bootstrap Toast”功能?
问题描述
我正在尝试将Bootstrap 4.2 Toast与 Angular 7 应用程序一起使用。我无法翻译 Angular 中的 Bootstrap 文档提供的 Jquery 示例。
目前,我在我的 HTML 模板中使用 Jquery 在我的组件准备好时调用$('.toast').toast('show')
以显示所有 DOM 祝酒词,但我确信这是错误的方式。我想在 .component.ts 中显示 toasts 通知ngOnInit()
,或者我可以在.component.ts中调用的其他函数。
例如,我想显示一个 toast 通知。
1 - 当前方法
toast.component.html
[...]
<div class="toast" id="toast" ...></div>
[...]
索引.html
[...]
<!-- Little hack to initialize Toast (according to the documentation) -->
<script>
$(document).ready(function(){
$('#toast').toast('show');
});
</script>
[...]
2 - 所需的方法
toast.component.html
[...]
<div class="toast" id="toast" ...></div>
[...]
toast.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
templateUrl: './toast.component.html'
})
export class ToastComponent implements OnInit {
ngOnInit() {
// Here is a good way to show a toast notification right here ?
}
}
这是一个显示当前行为的堆栈闪电战。
我知道这是最近的一个功能,但如果有人找到处理 Bootstrap Toasts 的好方法,那将非常感激 :)
解决方案
最后,我使用了ng-bootstrap库中的Toast 模块来实现这个目的:
<ngb-toast header="Notification header">
Content of the notification
</ngb-toast>
推荐阅读
- javascript - 未找到未捕获的表 alasql
- javascript - javascript元字符小写字母
- python - 如何使用 Watson Studio 获取 IBM COS Bucket 中的文件列表
- python - 如何在 python 中使用广义回归神经网络?
- bash - 从子组中获取每个匹配模式的数量
- sql - 使用 if 语句从不同的表更新表字段
- html - node.js - 上传图片到 MySQL 表
- javascript - 故障猫头鹰轮播设置
- ruby-on-rails - 更改 exception_handler gem 表的架构
- python - 如何在只有一个密码提示的情况下实现具有 root 权限的多个命令?