recursive dynamic template compilation in angular2

前端 未结 1 1377
一向
一向 2021-01-14 23:27

I\'ve based some of my work on the same problem described in here:

dynamic template to compile dynamic Component with Angular 2.0

How can I use/create dynami

相关标签:
1条回答
  • 2021-01-15 00:05

    If your change "text-editor" to "dynamic-detail" then your template will look like:

    <form>
      <dynamic-detail
         [propertyName]="'code'"
         [entity]="entity"
       ></dynamic-detail>
       <dynamic-detail
          [propertyName]="'description'"
          [entity]="entity"
       ></dynamic-detail>
    </form>
    

    DynamicDetail component doesn't have propertyName and entity properties. So you can add their.

    detail.view.ts

    export class DynamicDetail implements AfterViewInit, OnChanges, OnDestroy, OnInit
    { 
        @Input()  public propertyName: string;
        @Input()  public entity: any;
    

    Second part of solution is add this component to RuntimeComponentModule:

    type.builder.ts

    protected createComponentModule (componentType: any) {
      @NgModule({
        imports: [ 
          PartsModule,
          DynamicModule.forRoot() // this line
        ],
        declarations: [
          componentType
        ],
      })
      class RuntimeComponentModule {}
    
      return RuntimeComponentModule;
    }
    

    After that it should work Plunker Example

    0 讨论(0)
提交回复
热议问题