Get multiple ng-template ref values using contentChildren in angular 5

前端 未结 5 2556
孤城傲影
孤城傲影 2021-02-20 15:11

I am trying to pass multiple ng-template to my reusable component (my-table component), content projection. Now I need to get the reference value of ea

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-20 16:00

    I have built a table component in my library Easy Angular https://github.com/adriandavidbrand/ngx-ez/tree/master/projects/ngx-ez/src/lib/ez-table

    Each column can take a template via a ViewChild

    @ContentChild(TemplateRef)
    template: TemplateRef;
    

    The table uses ContentChildren to get the columns

    @ContentChildren(EzColumnComponent)
    columns: QueryList;
    

    and the table component passes the current item in with a context when rendering

    
    

    and is used like

    
      
        
          Use item view variable in template here
        
      
    
    

    Here is a demo of how it works

    https://stackblitz.com/edit/angular-npn1p1

    There is quite a bit to this table but all the source is up on GitHub.

提交回复
热议问题