简体   繁体   English

如何在 mat-select Angular Material 上显示预览值

[英]How to display a preview value on mat-select Angular Material

I am trying to create a compilation table where I have to select a value in from a mat-select.我正在尝试创建一个编译表,我必须在其中从 mat-select 中输入 select 一个值。

在此处输入图像描述

In the third column I have a list of values that I can choose在第三列中,我有一个可以选择的值列表

lunch:infoLunch[]=[{id_lunch: '',desc_lunch:''},
                     {id_lunch: 'TP1',desc_lunch:'Normale'},
                     {id_lunch: 'TP2',desc_lunch:'Senza carne'},
                     {id_lunch: 'TP3',desc_lunch:'Senza carne di maiale'},
                     {id_lunch: '14/1020',desc_lunch:'14/1020'}
  ];

And this is the html code of the column这是该列的html代码

<ng-container matColumnDef="pasto">
      <th mat-header-cell *matHeaderCellDef> Descrizione Pasto</th>
      <td mat-cell  *matCellDef="let studente">
        <mat-form-field>
          <mat-select [disabled]="studente.isAbsent || studente.isGuest" (selectionChange)="checkCheckPastovalue($event, studente)" panelClass="example-panel-dark-blue">
            <mat-option *ngFor="let cust of lunch"
                        [value]="cust"> {{studente.isAbsent || studente.isGuest ?  '': cust.desc_lunch}}
            </mat-option>
          </mat-select>
        </mat-form-field>
      </td>
    </ng-container>

I have an external json from db with set or empty values我有一个来自 db 的外部 json 具有设置或空值

    {
                      "idStudenti": 1,
                        "nome": "John",
                        "cognome": "Doe",
                        "isChecked": true,
                        "CodLunch": "TP1",
                        "DescLunch": "Normale",
                        "isGuest": false,
                        "hostSchool": "",
                        "isAbsent": false
                    },
                    {
                        "idStudenti": 2,
                        "nome": "Giada",
                        "cognome": "Doe",
                        "isChecked": false,
                        "CodLunch": "",
                        "DescLunch": "",
                        "isGuest": false,
                        "hostSchool": "",
                        "isAbsent": false
                    }

How can I display the current value of the json on the mat-select?如何在 mat-select 上显示 json 的当前值?

You got two options for this:你有两个选择:

--- OR --- - - 或者 - -

  • Have a property and bind it so that you can display the information outside the table in a nice format拥有一个属性并绑定它,这样你就可以在表格之外以漂亮的格式显示信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 角材料垫选择设置默认选择值 - Angular Material mat-select set default selected value 赛普拉斯 e2e 测试与 Angular 材料垫选择不能设置 select 值 - Cypress e2e test with Angular Material mat-select can't set a select value 如何将Angular 5 Material Select下拉菜单(mat-select)更改为打字稿代码/文件中的选项之一? - How can I change an Angular 5 Material Select dropdown (mat-select) to one of the options in typescript code/file? 材质角在滚动选择垫并隐藏时滚动到顶部 - Material Angular scrolls to top on opening of mat-select and hides 无法设置设置 Angular 材质垫-选择默认选项 - Cannot set set Angular Material mat-select default option 如何为 mat-select 设置默认值? - How to set default value for mat-select? <mat-select>使用angular中的getElementById获取时没有value属性,如何获取值?</mat-select> - <mat-select> don't have value attribute when getting it using getElementById in angular , how to get the value? Angular mat-select 不拾取默认值 - Angular mat-select not picking up default value 如何在 Angular 7+ 的 Mat-Select 选项中获取选定值的选定索引 - How to get selected index of selected value in Mat-Select Option in Angular 7+ 如何将 Json 对象中的值显示到 Mat-Select 中 - How to display Values from a Json Object into a Mat-Select
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM