角材料2:具有自定义内容的垫自动完成

时间:2018-07-26 20:52:45

标签: javascript angular autocomplete angular-material2

我有一个带有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)函数有问题,当然,这是行不通的。

0 个答案:

没有答案