描述如题,求大神指点代码父组件html:<ng-container *ngComponentOutlet="switchComponent"></ng-container>ts:public switchComponent = null;constructor() {this.switchComponent = PatientRecordComponent;}子组件<div *ngif="false">ssss</div>尝试解决方法父组件html:<ng-container *ngComponentOutlet="switchComponent; ngModuleFactory: myModule;"></ng-container>ts:import {NgModuleFactory, Compiler} from '@angular/core';import {PatientRecord} from '../common/patient/record/record.module';public switchComponent = null;myModule: NgModuleFactory<any>;constructor(compiler: Compiler) {this.myModule = compiler.compileModuleSync(PatientRecord);
this.switchComponent = PatientRecordComponent;}
1 回答
慕仙森
TA贡献1827条经验 获得超8个赞
你需要在AppModule或者你的这个组件对应的module里面导入CommonModule
import { CommonModule } from '@angular/common';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
CommonModule
],
providers: [],
bootstrap: [AppComponent]
})
因为*ngFor *ngIf这些指令是在CommonModule中定义,并且导出来给外部用的。
添加回答
举报
0/150
提交
取消