【发布时间】:2017-12-06 09:08:29
【问题描述】:
我有自动完成输入
<div formArrayName="addresses">
<div class="row"
*ngFor="let itemrow of searchForm.controls.addresses.controls; let i=index"
[formGroupName]="i">
<mat-form-field>
<input type="text"
class="form-control" id="address"
formControlName="address"
matInput
[matAutocomplete]="auto"
(keyup)="getESRI($event.target.value)"
(focusout)="bindLocation($event.target.value)">
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let option of testLocation"
[value]="option.text">
{{ option.text }}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</div>
</div>
"testlocation":[{"text":"Euronet","magicKey":"dHA9MSNubT1FdXJvbmV0I2NzPTE5OjExI3NjPURFVQ==","isCollection":true},{"text":"Euronet","magicKey":"dHA9MSNubT1FdXJvbmV0I2NzPTE5OjExI3NjPURFVQ==","isCollection":true}]
当我尝试添加值 [value]="option.magicKey 时,它会在我选择选项时显示在输入 option.magicKey 中。我只需要option.magicKey 作为值,option.text 作为输入选项。否则如何将option.magicKey作为参数添加到bindLocation($event.target.value)函数中?
【问题讨论】:
标签: angular autocomplete angular-material selectedvalue