html - 读取 <mat-option> angular 的值

标签 html angular typescript angular2-template

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>

typescript : 我有:

  RpiIp = '';

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

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

最佳答案

您需要将 ngModel 放在 mat-select 上,而不是放在 mat-option

关于html - 读取 <mat-option> angular 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57331015/

相关文章:

javascript - 如何在 ionic 应用程序中设置 setCancelable(false)?

javascript - 为什么我的 .draggable 方法返回错误?

javascript - 在点击 td 后尝试获取 td 行文本

javascript - 如何在 Angular 2 中使用 ngIf-else 中的表达式

javascript - Angular 5从父组件中的数组中删除对象

javascript - NestJS 在生产中启用 cors

node.js - 如何在 NestJS 中从查询中获取参数

html - ExtJS - 行渲染器 - 如果单元格具有特定值,则突出显示整行

html - css div水平对齐

angular - NullInjectorError : R3InjectorError(DynamicTestModule)[ApiService -> HttpClient -> HttpClient]: NullInjectorError: No provider for HttpClient