angular5.2 用ngComponentOutlet 添加的组件没有bind ngif?

描述如题,求大神指点
代码
父组件
html:
<ng-container *ngComponentOutlet="switchComponent"></ng-container>
ts:
public switchComponent = null;
constructor() {

this.switchComponent = PatientRecordComponent;

}
子组件
<div *ngif="false">ssss</div>

https://img1.mukewang.com/5ca41a5e000108ae08000187.jpg

尝试解决方法
父组件
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;

}


明月笑刀无情
浏览 287回答 1
1回答

慕仙森

你需要在AppModule或者你的这个组件对应的module里面导入CommonModuleimport { CommonModule } from '@angular/common';@NgModule({&nbsp; declarations: [&nbsp; &nbsp; AppComponent&nbsp; ],&nbsp; imports: [&nbsp; &nbsp; BrowserModule,&nbsp; &nbsp; CommonModule&nbsp; ],&nbsp; providers: [],&nbsp; bootstrap: [AppComponent]})因为*ngFor *ngIf这些指令是在CommonModule中定义,并且导出来给外部用的。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript