How to render multiple ng-content inside an ngFor loop using Angular 4?

后端 未结 1 440
孤独总比滥情好
孤独总比滥情好 2020-12-07 23:26

I\'m trying to display two differents ng-content inside two ngFor loops. But as described in this answer, Angular can\'t project ng-content multipl

1条回答
  •  庸人自扰
    2020-12-08 00:02

    The best option in your case would be trancluding ng-template by using ngTemplateOutlet like:

    
      
        
    {{line.name}}
    {{element.name}}

    app-table.component.ts

    @Component({
      selector: 'app-table',
      template: `
        
    ` }) export class AppTableComponent { @Input() data: any; @ContentChild('lineHeader') lineHeaderTmpl: TemplateRef; @ContentChild('lineContent') lineContentTmpl: TemplateRef; }

    Stackblitz Example

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