我正在将Angular 6与Material组件一起使用。 由于更改了代码(不确定何时开始),因此我的select元素表现得很奇怪。
如您所见,直到我单击顶部的自动填充功能,地址的选择框才会打开。我也可以单击另一个元素,这也将导致选择项打开。
可能是什么原因造成的?我真的不知道。
<mat-form-field class="full-width">
<!-- <input matInput placeholder="{{ 'mainapp.shipment.pickupaddress' | translate }}"
attr.aria-label="{{ 'mainapp.shipment.pickupaddress' | translate }}" [matAutocomplete]="auto_p"
formControlName="address_from"
>
<mat-autocomplete #auto_p="matAutocomplete" autoactiveFirstOption [displayWith]="displayAddress">
<mat-option *ngFor="let pickup of filteredAddresses_pickup | async" [value]="pickup">
<span>{{pickup.name}},{{pickup.postalcode}},{{pickup.country}}</span>
</mat-option>
</mat-autocomplete>-->
<mat-label>{{ 'mainapp.shipment.pickupaddress' | translate }}</mat-label>
<mat-select formControlName="address_from">
<!--<mat-option *ngFor="let food of foods" [value]="food.value">
{{food.viewValue}}
</mat-option>-->
<mat-option value="no_change" *ngIf="shipment_id">{{ 'mainapp.shipment.address_selector.no_change' | translate }}</mat-option>
<mat-option value="update" *ngIf="shipment_id" (click)="openAddAddressDialog('from',fromAddress)">{{ 'mainapp.shipment.address_selector.update' | translate }}</mat-option>
<mat-option value="new" (click)="openAddAddressDialog('from')">{{ 'mainapp.shipment.address_selector.new' | translate }}</mat-option>
<mat-option value="new_entered" [ngClass]="addressFromSelected ? 'none': 'hide_element'">{{addressFromSelectedLabel}}</mat-option>
<mat-option value="visiting_address">{{ 'mainapp.shipment.address_selector.visiting_address' | translate }}</mat-option>
<mat-optgroup label="Recent addresses">
<mat-option *ngFor="let address of _addresses | async" [value]="address">
{{ displayAddress(address) }}
</mat-option>
</mat-optgroup>
</mat-select>
</mat-form-field>