读取 <mat-option> angular 的值

神鹰IV

HTML:

  <mat-icon class="fab fa-raspberry-pi"></mat-icon>
  <mat-form-field>
    <mat-select placeholder="Rpi">
      <mat-option>Choose</mat-option>
      <mat-option *ngFor='let pi of myRpis' [(ngModel)]="RpiIp" ngDefaultControl [value]="pi.RPI_IP"
        (click)="getPins()">
        {{pi.LABEL}}
      </mat-option>
    </mat-select>
  </mat-form-field>

打字稿:我有:

  RpiIp = '';

  getPins() {
    console.log(this.RpiIp);
    this.doneFetching = true;
  }

控制台打印一个空值(值不变)。错误在哪里?为什么价值没有改变?

神鹰IV

基于此答案,正确答案如下所示:

 <mat-icon class="fab fa-raspberry-pi"></mat-icon>
      <mat-form-field>
        <mat-select placeholder="Rpi" [(value)]="RpiIp">
          <mat-option>Choose</mat-option>
          <mat-option *ngFor='let pi of myRpis' ngDefaultControl [value]="pi.RPI_IP" (click)="getPins()">
            {{pi.LABEL}}
          </mat-option>
        </mat-select>
      </mat-form-field>

感谢:D

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

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

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

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

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

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

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

Angular 2在更改时获取<option>的值

Angular 6 读取空输入值

从.mat文件读取

Angular 12 - Mat-Dialog 不显示表中的值

Angular 5 Material mat 选择:根据所选值进行过滤,

设置值后,Angular Material mat-select不刷新

从Angular 6 mat-selection-list获取选定值的列表

Angular Material => 从 formControlName 设置 mat-select 的值

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

Angular Material 2自动完成,mat-option元素不会触发键入事件

Angular Material v6 Mat-Footer-“无法读取未定义的属性'template'”

Angular 无法读取“未定义”的值 - 无法在 setTitle() 方法中读取“casestudy”的值?

如何从Angular mat-select中获取先前值和新值?

在Python中读取.mat文件

犰狳读取 MAT 文件错误

Angular 6:TypeError:无法读取未定义的属性“值”

Angular 4 嵌套对象无法读取空值错误

Angular Reactive Forms - 从数组中读取/设置值

Angular 8设置ngSstyle并读取offsetwidth给出了旧值

无法读取未定义的Angular CLI的属性“值”

Angular - 读取表格中复选框的行值

如何使用angular2中的mat-input对在mat-table列中输入的值求和

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

当不再在 Angular 中悬停 mat-option 时,有没有办法调用函数?

Angular 6 Material <mat-select>使用窗体控件设置多个默认值