为什么不能选择mat-select的mat-option?

DT

我创建一个对话框来插入数据:

这是html页面:

<input type="hidden" ngModel="{{au.id}}" name="id">
<mat-form-field>
  <mat-label>Name</mat-label>
  <input matInput [(ngModel)]="au.name" name="name">
</mat-form-field>
<br />
<mat-form-field>
  <mat-label>Sex</mat-label>
  <mat-select [(ngModel)]="au.sex" name="sex">   
      <mat-option [value]="nam">Nam</mat-option>
      <mat-option [value]="nu">Nu</mat-option> 
  </mat-select>
</mat-form-field>
<br />
<mat-form-field>
  <mat-label>Birth Day</mat-label>
  <input matInput type="date" [(ngModel)]="au.birthDay" name="birthDay">
</mat-form-field>
<br />
<button mat-raised-button (click)="Save()">save</button>

这是ts文件:

export class Author {
  id: string;
  name: string;
  sex: string;
  birthDay: Date;
}
export class Author_PopupComponent {
  au: Author = new Author();
}

mat-select 显示2个值,但是我选择一个选项,它无法显示在控件中选择的值。

为什么不能选择mat-optionmat-select

林文森

方法1

更换[value]value在你<mat-option [value]="nam">Nam</mat-option>当你的价值不是动态的。

方法2

在使用时[value],将您的mat-option值(字符串)用单引号引起来,将其视为动态值。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在<mat-select> <mat-option>内部使用[innerHTML]

<mat-select>中没有足够的空间。如何添加多行<mat-option>?

在 mat-select/mat-option 中以编程方式触发 [compareWith]

Mat-option出现在页面底部,而不是出现在mat-select下

有條件地將 mat-option 添加到 mat-select

角材料,以选择mat-list-option并显示所选mat-list-option的相应数据

Angular Material表单控件mat-select-mat-option,设置用于更新项目的默认选项吗?

如何在Angular 5的Mat-Select Option中获取选定值的ID

选择mat-option(角度)时如何调用方法?

Angular 7:使用mat-select:动态获取mat-option的选项会创建一个永无止境的循环

带删除功能的 mat-option

读取 <mat-option> angular 的值

为什么Angular Mat Table 2选择模型失败?

如何使“ mat-select”只读?

OpenCV-为什么光流不能与出队<Mat>一起使用?

为什么我不能在表单标签内移动 mat-slide-toggle?

在 Angular 中,不会为 angular mat-option 调用 onSelectionChange

要在mat-list-option中更改文本颜色

如何解决'mat-list-option'是Angular组件?

如果 'mat-option' 是一个 Angular 组件,则验证

角度指令-ElementRef-无法从mat-form-field中选择mat-select

一旦在Angular 8中选择了Mat-Table,就禁用Mat-Select选项

根据选择的mat-select值对mat-table进行排序

为什么默认值不会在 Mat Select 下拉列表中呈现?

在此示例中,为什么ngx-mat-select-search不使用动态数据?

从模板中选择 mat-select 的初始值

如何从Mat-Select中获得取消选择的值

mat-select 用于日期(日-月-年)选择?

为什么设置<select>和<option>元素的样式如此困难?