Roland Rácz
Roland Rácz

Reputation: 2999

Angular: ContentChild is undefined

I'm using Angular 5 and trying to create some kind of dynamic component.

I have a simple directive, MyColumnDef (with the selector [myColumnDef]). There is nothing special about it. I'm using it in:

parent.compontent.html:

<div>
  <my-table>
    <ng-template myColumnDef>
      Lorem ipsum.
    </ng-template>
  </my-table>
</div>

my-table.component.html:

<div>
  Something:
  <ng-container *ngTemplateOutlet="temp"></ng-container>
</div>

In my-table.component.ts:

 @ContentChild(MyColumnDef, {read: TemplateRef}) temp;

This should show the 'Lorem ipsum.' text, but there is nothing, actually the temp is undefined (according to console.log in ngAfterViewInit), and I don't know why. Am I missing something?

Upvotes: 4

Views: 2444

Answers (1)

Roland R&#225;cz
Roland R&#225;cz

Reputation: 2999

I didn't put the directive in its own module's exports array.

Upvotes: 6

Related Questions