angular - ng-bootstrap - 模态组件上的容器属性
问题描述
在 ng-bootstrap 站点上,Modal component
->Api
有一条信息表明 modal 具有conatainer
带有描述的属性:“ An element to which to attach newly opened modal windows
”。这是否意味着我可以将打开的模式直接附加到我的 HTML 网站上指定的 div id 元素?
如果是这样,如何在 Angular 项目中实现这一点?在我的项目中,我在 modal-basic.html 中添加了以下代码:
<div id="test" class="col-6">Some text</div>
并添加了属性容器:
this.modalService.open(content, {container: 'test',ariaLabelledBy: 'modal-basic-title'}).result.then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
但我收到一个错误:
NgbdModalBasic.html:28 ERROR Error: The specified modal container "test" was not found in the DOM.
at NgbModalStack.push../node_modules/@ng-bootstrap/ng-bootstrap/fesm5/ng-bootstrap.js.NgbModalStack.open (ng-bootstrap.js:6417)
at NgbModal.push../node_modules/@ng-bootstrap/ng-bootstrap/fesm5/ng-bootstrap.js.NgbModal.open (ng-bootstrap.js:6681)
at NgbdModalBasic.push../src/app/modal-basic.ts.NgbdModalBasic.open (modal-basic.ts:16)
at Object.eval [as handleEvent] (NgbdModalBasic.html:28)
at handleEvent (core.js:10258)
at callWithDebugContext (core.js:11351)
at Object.debugHandleEvent [as handleEvent] (core.js:11054)
at dispatchEvent (core.js:7717)
at core.js:8161
at HTMLButtonElement.<anonymous> (platform-browser.js:995)
请问你能帮帮我吗?
解决方案
指定容器元素时,您需要传入元素或选择器或两者的组合。在您的情况下,您希望访问 ID 为 test 的元素。容器属性应设置为“#test”。
this.modalService.open(content, {container: '#test',ariaLabelledBy: 'modal-basic-title'}).result.then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
推荐阅读
- report - Splunk Query 列出 Reports 的使用情况
- flutter - 从物料路线返回后设置状态
- reactjs - 如何使用 setState 单独从末尾删除数组?
- c# - 使用 Nginx 的 gRPC 通信卡住
- c++ - 为什么用 constexpr 声明的引用可以绑定到 Indeterminate 值变量?
- python - Pysolar:计算辐照:它涵盖的时间跨度
- python - Flask API 可在本地设备上工作,但不能在 heroku 上工作(向 flask api 发送大字符串)
- javascript - nvd3 multiBarChart中键的标题
- apache-spark - 在 Spark 中执行以“WITH”关键字开头的 SQL 语句
- docker - 无法使用前端 dockerfile.v0 解决:无法读取 dockerfile DOCKER 问题