小编Jos*_*ham的帖子

Angular 9 CDK 门户错误:必须提供要附加的门户

我在处理看似简单的事情时遇到了困难。我试图在 Angular 9 中打开一个包含一些 html 的新窗口。每次运行时,我都会看到一个窗口弹出一秒钟,然后失败并抛出以下错误:

Error: Must provide a portal to attach
    at throwNullPortalError (portal.js:23)
    at DomPortalHost.attach (portal.js:320)
    at GraphPopoutComponent.ngOnInit (graph-popout.component.ts:43)
    at callHook (core.js:4686)
    at callHooks (core.js:4650)
    at executeInitAndCheckHooks (core.js:4591)
    at refreshView (core.js:11814)
    at refreshDynamicEmbeddedViews (core.js:13154)
    at refreshView (core.js:11819)
    at refreshComponent (core.js:13229)
Run Code Online (Sandbox Code Playgroud)

在有人问之前:

  • 是的,我已将 PortalModule 包含在我的 app.module.ts 中
  • 角度 9.0.7
  • 角度/cdk、角度/材料 9.1.3
  • 我确实有嵌套模块,这会导致 PortalModule 出现问题吗?

这是我的代码供参考:

graph.component.html

.
.
.
<app-graph-popout *ngIf="openPortal">
  <h1>IT WORKS</h1>
</app-graph-popout>
Run Code Online (Sandbox Code Playgroud)

图.组件.ts

.
.
.
togglePortal() {
    this.openPortal = true;
  }
Run Code Online (Sandbox Code Playgroud)

graph-popout.component.ts

@Component({
  selector: 'app-graph-popout', …
Run Code Online (Sandbox Code Playgroud)

angular-material angular angular-cdk

3
推荐指数
1
解决办法
2835
查看次数

标签 统计

angular ×1

angular-cdk ×1

angular-material ×1