【问题标题】:Angular Material: my-select - selectionChange角材质:我的选择 - selectionChange
【发布时间】:2018-11-11 17:47:48
【问题描述】:

在我的 Angular 组件中,我创建了这个 formGroup:

this.form = new FormGroup({         
  address: new FormGroup({
    ...
    country: new FormControl('', [Validators.minLength(2)]),
    ....
  }),

在我的模板中我尝试过这个:

   <mat-form-field>
        <mat-select placeholder="Land" formControlName="country" (selectionChange)="countryChanged(country)">
            <mat-option *ngFor="let countryType of countryTypes" [value]="countryType">
                {{countryType | translate}}
            </mat-option>
        </mat-select>
   </mat-form-field>

但它不能像这样工作 - 国家总是未定义 countryChanged(country)

【问题讨论】:

  • 你的countryChanged是做什么的?
  • 您可以使用this.form.address.valuechanges.subscribe...,如果您想处理表单中的任何更改,请使用this.form.valuechanges
  • countryChanged 从服务器获取国家的省类型

标签: angular angular-material


【解决方案1】:

country 替换为 $event 就可以了。

(selectionChange)="countryChanged($event)"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-09
    • 2020-07-18
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 2022-11-28
    • 2019-03-08
    相关资源
    最近更新 更多