本文介绍了Mat-autocomplete-如何访问所选选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道[value]
存储选定的对象(在我的情况下为Offer).根据材料文档,optionSelected
会发出一个事件.我尝试了[optionSelected] = "fooFn"
,但它不存在.我只想访问Offer对象.谢谢!
I know that [value]
stores the selected Object (Offer in my case). According to materials documentation, optionSelected
emits an event. I tried [optionSelected] = "fooFn"
but it doesn't exist. I just want to access the Offer object. Thanks!
offer-search.component.html:
offer-search.component.html:
<h5 #offerP>option - autoComplete</h5>
<mat-form-field id="form-field">
<input type="text" matInput [formControl]="myControl" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn">
<mat-option *ngFor="let option of filteredOptions$ | async" [value]="option">
{{ option.foodItem.name }}
</mat-option>
</mat-autocomplete>
</mat-form-field>
推荐答案
您可以像这样使用它:
<mat-autocomplete #auto="matAutocomplete" (optionSelected)='getPosts($event.option.value)'>
WORKING DEMO
这篇关于Mat-autocomplete-如何访问所选选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!