我在处理看似简单的事情时遇到了困难。我试图在 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)
在有人问之前:
这是我的代码供参考:
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)