为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

明月笑刀无情 2019-03-14 18:15:39
描述如题,求大神指点代码父组件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中定义,并且导出来给外部用的。


查看完整回答
反对 回复 2019-04-03
  • 1 回答
  • 0 关注
  • 286 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信