在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML5  HTML/ angular5.2 用ngComponentOutlet 添加的組件沒(méi)有bin

angular5.2 用ngComponentOutlet 添加的組件沒(méi)有bind ngif?怎么破?

描述如題,求大神指點(diǎn)
代碼
父組件
html:
<ng-container *ngComponentOutlet="switchComponent"></ng-container>
ts:
public switchComponent = null;
constructor() {

this.switchComponent = PatientRecordComponent;

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

clipboard.png
嘗試解決方法
父組件
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;

}

回答
編輯回答
糖豆豆

你需要在AppModule或者你的這個(gè)組件對(duì)應(yīng)的module里面導(dǎo)入CommonModule

import { CommonModule } from '@angular/common';
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    CommonModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})

因?yàn)?code>*ngFor *ngIf這些指令是在CommonModule中定義,并且導(dǎo)出來(lái)給外部用的。

2018年3月19日 03:21