使垫选项和垫选择具有不同的UI

时间:2019-12-12 12:55:20

标签: angular angular-material

我在下拉列表中有电话号码的国家/地区代码。目前,我希望所选项目仅包含标志图像或代码。下拉列表中包含图片,国家/地区代码和国家/地区名称。

<mat-form-field appearance="outline" fullWidth>
  <mat-label>Country Code</mat-label>
  <mat-select #matSelect [(value)]="selectedCode" [formControlName]="helperService.appConstants.countryCode" (selectionChange)="changeSelection(selectedCode)" required>
    <mat-option *ngFor="let code of countryCode" [value]="code.calling_code" (keypress)="numberOnly($event)&&phoneNumberValid(registerObj.userForm)">
      <img with="10px" height="10px" src="{{code.flag}}"> {{ code.country }} ({{code.calling_code}})
    </mat-option>
  </mat-select>
</mat-form-field>

那是我正在编写的代码。我也有当前用户界面的图像。它们附在下面。

enter image description here enter image description here

我希望所选项目看起来像下面的图像。我不知道要更改什么,以便所选项目仅显示图像。

enter image description here

1 个答案:

答案 0 :(得分:1)

尝试添加<mat-select-trigger>

    <mat-select-trigger>
       <img with="10px" height="10px" src="{{code.flag}}">
    </mat-select-trigger>

您的代码如下:

<mat-form-field appearance="outline" fullWidth>
  <mat-label>Country Code</mat-label>
  <mat-select #matSelect [(value)]="selectedCode" [formControlName]="helperService.appConstants.countryCode" (selectionChange)="changeSelection(selectedCode)" required>
    <!-- Add mat-select-trigger here start -->
    <mat-select-trigger>
       <img with="10px" height="10px" src="{{code.flag}}">
    </mat-select-trigger>
     <!-- Add mat-select-trigger here end -->
    <mat-option *ngFor="let code of countryCode" [value]="code.calling_code" (keypress)="numberOnly($event)&&phoneNumberValid(registerObj.userForm)">
      <img with="10px" height="10px" src="{{code.flag}}"> {{ code.country }} ({{code.calling_code}})
    </mat-option>
  </mat-select>
</mat-form-field>

恭喜您提出了一个格式正确的问题!