我有一个带有mat-autocomplete
的自定义组件
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
<mat-option *ngFor="let item of items" [value]="item">
<ng-container *ngTemplateOutlet="optionTemplate;context:createContext(item)"></ng-container>
</mat-option>
</mat-autocomplete>
我使用自定义模板在mat-option
内设置文本格式
<ng-template #optionTemplateRef let-other="item">
{{other.value}}
</ng-template>
是否可以在模板中移动mat-option
?
我想创建类似这样的东西
<ng-template #optionTemplateRef let-other="item">
<mat-option *ngFor="let item of items" [value]="item">
{{other.value}}
</mat-option>
</ng-template>
我想为mng-container
使用自定义模板。
我可以将项目从组件传递到自定义模板,但是selected($event)
函数有问题,当然,这是行不通的。