When using transclusion in an angular2 component, it appears that my 'ViewChildren' is not able to detect these components. When I make a component where I define the same components directly then it works fine. Does anyone now a way to get this work?
            Asked
            
        
        
            Active
            
        
            Viewed 1,543 times
        
    2
            
            
        - 
                    1FYI, we're using the term *content projection* instead of transclusion now. – drew moore Aug 30 '16 at 17:18
- 
                    Thanks for this nice addition! – Joris Brauns Sep 22 '16 at 13:07
2 Answers
5
            You can query transcluded content using @ContentChild() or @ContentChildren().
@ViewChild() and ´@ViewChildren()` only allow to query element in the components template.
See also angular 2 / typescript : get hold of an element in the template
 
    
    
        Community
        
- 1
- 1
 
    
    
        Günter Zöchbauer
        
- 623,577
- 216
- 2,003
- 1,567
0
            
            
        I tried to do this with my error messages component too. Actually you just need to use ContentChildren decorator instead of ViewChildren. It is made special for ng-content elements. As a result you will get QueryList which is iterable object of your components or elements.
 
    
    
        Lyubimov Roman
        
- 1,269
- 15
- 27
