Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursively-placed components not displaying

Tags:

angular

I have the following component, which displays child components of its own type for each element in an array.

@Component({
  selector:'pane',
  template: `
       <pane [item]="item">
           <div> 
               <pane *ngFor="#subItem of item.subItems" [item]="subItem"></pane>
           </div>
           <div innerHtml="item.getContent()"></div>
       </pane>
   `
)}   
export class Pane {
  @Input() item: any;
}

But the pane components inside the ngFor are not being displayed as expected - I see the correct number of pane elements, but they are not populated with the template contents.

like image 964
drew moore Avatar asked Dec 03 '15 00:12

drew moore


1 Answers

It's because you need to declare the component's own type in the directives property of the decorator, as you do with any other directive.

Adding:

directives: [Pane]

to your component metadata results in the expected behavior.

like image 147
drew moore Avatar answered Sep 28 '22 08:09

drew moore