在其他元素被点击之前,Angular Select才会打开

我正在将Angular 6与Material组件一起使用。 由于更改了代码(不确定何时开始),因此我的select元素表现得很奇怪。

Video of weird behavior

如您所见,直到我单击顶部的自动填充功能,地址的选择框才会打开。我也可以单击另一个元素,这也将导致选择项打开。

可能是什么原因造成的?我真的不知道。

      <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>
t456456 回答:在其他元素被点击之前,Angular Select才会打开

您不能对多个元素使用相同的formControlName。 观看评论!我删除了很多可见性的代码。

<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" />// This is address_from
   <mat-label>{{ 'mainapp.shipment.pickupaddress' | translate }}</mat-label>
   <mat-select formControlName="address_from">
      // and this address_from needs to be something different
      <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>
本文链接:https://www.f2er.com/3159189.html

大家都在问