【发布时间】: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 从服务器获取国家的省类型