Passing for variable to ng-content

前端 未结 1 825
花落未央
花落未央 2021-01-02 11:28

How do I pass an ngFor variable to the ng-content template.

Example, the containing-component:

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-02 12:19

    You can not use ng-content as dynamic template. Use ng-template instead

    export class ContainingComponent {
    
      ...
    
      @ContentChild(TemplateRef, {static: true}) 
      @Input() itemTemplate: TemplateRef;
    }
    

    So you can reference dynamic template into containing-component. In this case, you can wrap ng-template over content-component

    
    
    
    
    
        
        
    
    

    Or use ng-template directly:

    
    
    
    
      

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