I built a tooltip directive by following this article,
I am trying to pass templateRef
to the tooltip directive.
Below is my shared component,
at ts,
@Input() fieldPreferences: IFieldPreference[];
at html,
<mat-selection-list #list>
<mat-list-option
*ngFor="let preference of fieldPreferences"
[selected]="preference.selected"
(click)="showPreferenceChanged(list)"
[value]="preference.field">
{{preference.field}}
</mat-list-option>
</mat-selection-list>
At parent,
<mat-icon tooltip [content]="template">settings</mat-icon>
<ng-template #template>
<field-preferences
[fieldPreferences]="fieldPreferences"
(selectedFields)="showPreferenceChanged($event)">
</field-preferences>
</ng-template>
Tooltip is showing up with no content (i.e) mat-list-option
is not generated.
According to this SO OP, the problem is with *ngFor
and ng-template
.
I tried changing it to,
<mat-selection-list #list>
<mat-list-option ngFor let-preference [ngForOf]="fieldPreferences"
[selected]="preference.selected"
(click)="showPreferenceChanged(list)"
[value]="preference.field">
{{preference.field}}
</mat-list-option>
</mat-selection-list>
Still, tooltip is rendered with no content.