Javascript @ViewChild未创建角度CDK门户?
尝试创建CDK门户,如下所示:Javascript @ViewChild未创建角度CDK门户?,javascript,angular,typescript,angular-cdk,Javascript,Angular,Typescript,Angular Cdk,尝试创建CDK门户,如下所示: @ViewChild(CdkPortal) portal; 但是,门户在ngAfterViewInit方法中未定义: ngAfterViewInit(): void { // Create a portalHost from a DOM element this.portalHost = new DomPortalHost( document.querySelector('#actions'), this.compon
@ViewChild(CdkPortal) portal;
但是,门户在ngAfterViewInit
方法中未定义:
ngAfterViewInit(): void {
// Create a portalHost from a DOM element
this.portalHost = new DomPortalHost(
document.querySelector('#actions'),
this.componentFactoryResolver,
this.appRef,
this.injector
);
console.log("THE PORTAL IS: ", this.portal)
有什么想法吗?忘记导入门户模块:
import { PortalModule } from '@angular/cdk/portal';
...
@NgModule({
imports: [ PortalModule, MaterialModule, BrowserModule, FormsModule ],
declarations: [ ToolbarActionsComponent, AppComponent, HelloComponent ],
bootstrap: [ AppComponent ]
})