【发布时间】:2018-07-27 03:45:56
【问题描述】:
当我第一次在其下拉列表中选择城市时,该值不会出现。当我在第二个下拉列表中选择国家时,第一个下拉列表中的第一个值出现,第二个下拉列表中的第二个值不出现。关于我的代码中的问题有什么建议吗?
代码.ts
updateForm(event: MatOptionSelectionChange , city: City, country_id: Country, region_id: Region) {
if (event.source.selected) {
this.Myform['controls']['country_id'].patchValue(this.country_id.value);
this.Myform['controls']['city'].patchValue(this.city.value);
}
}
code.html
<input formControlName="country_id" id="country_id" matInput placeholder="Select Region*" aria-label="State" [matAutocomplete]="auto"
autoActiveFirstOption [formControl]="country_id">
<mat-autocomplete #auto="matAutocomplete">
<mat-option (onSelectionChange)="updateForm($event,country.id,'country_id')" id="country_id" *ngFor="let country of filteredOptionsCountry | async" [value]="country.name">
{{ country.name }}
</mat-option>
</mat-autocomplete>
<input formControlName="city" id="city" matInput placeholder="Select City*" aria-label="State" [matAutocomplete]="auto1"
autoActiveFirstOption [formControl]="city">
<mat-autocomplete #auto1="matAutocomplete">
<mat-option (onSelectionChange)="updateForm($event,city.id,'city')" *ngFor="let city of filteredOptionsCity | async" [value]="city.name">
{{ city.name }}
</mat-option>
</mat-autocomplete>
谢谢!
【问题讨论】:
标签: angular typescript autocomplete angular-material