angular - 使垫子选项和垫子选择具有不同的用户界面

标签 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

最佳答案

尝试添加 <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>

恭喜你提出了一个非常好的问题!!

关于angular - 使垫子选项和垫子选择具有不同的用户界面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59305097/

相关文章:

javascript - Material 升级后 AngularJS 自定义指令双向绑定(bind)被破坏

angular - 垫表根据条件显示行

angular-material - 弹性布局 : Push last item to the end horizontally

javascript - JS : Searching a list of objects inside another

typescript - 网络 Storm "Warning:File was not compiled because there is no a reference from tsconfig.json"

angular - 微型前端架构建议

angular - 升级到angular 12后,所有 Material 成分都是 "not a known element"

Angular Material - 自定义自动完成组件

angular - 选择器在 Angular 2 中究竟做了什么?

angular - 类型错误 : Converting circular structure to JSON when trying to POST request