javascript - 非法调用实例化 BS 模态
问题描述
我试图通过组件以角度调用引导模式,而不是使用它的 HTML 属性。我收到一个错误(即非法调用)。
零件:
@ViewChild('myModal') div:any;
ngAfterViewInit() {let bs = new bootstrap.Modal(this.div);}
HTML
<div class="modal-content" #myModal>...</div>
解决方案
您需要使用该服务而不是创建它的一个实例。对代码进行以下更改:
import {NgbModal, ModalDismissReasons} from '@ng-bootstrap/ng-bootstrap';
...
...
@ViewChild('myModal') div:any;
constructor(private modalService: NgbModal )
ngAfterViewInit() {
// make sure you get the instance of the child.
this.modalService.open(this.div);
}
推荐阅读
- java - 无法在 Android 中将 java 字符串转换为 JSON 数组
- reactjs - 如何从firebase中的集合中获取所有图片?
- javascript - 使用通过 React-router 传入 url 的参数
- python - 如何将 OpenCV 函数中的一维数组与 CNN 中的扁平向量连接起来
- python - Pyspark DataFrame 计算另一列中某列值的出现次数
- sql-server - SQL Azure 远程过程
- python-3.x - Gunicorn 没有自动启动
- database - 耳语数据库的替代品
- java - 如何显示与长按下图搜索图标时相同的自定义视图?
- python - 为什么 `asyncio.run()` 在 Python 3.8 中永远不会返回?