ng-bootstrap - 模态组件的容器属性

ng-bootstrap - Container properties on Modal Component

在 ng-bootstrap 站点上,Modal component -> Api 有一条信息表明模态具有 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)}`;
});