我通过遵循this文章构建了一个工具提示指令,
我正在尝试将templateRef
传递给tooltip指令。
下面是我的共享组件,
在ts,
@Input() fieldPreferences: IFieldPreference[];
在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>
在家长,
<mat-icon tooltip [content]="template">settings</mat-icon>
<ng-template #template>
<field-preferences
[fieldPreferences]="fieldPreferences"
(selectedFields)="showPreferenceChanged($event)">
</field-preferences>
</ng-template>
工具提示未显示任何内容(即未生成mat-list-option
)。根据这个SO OP,问题出在*ngFor
和ng-template
上。
我试着改成,
<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>
尽管如此,工具提示仍呈现为无内容。
https://stackoverflow.com/questions/52844440
复制相似问题