我在mat-form-field
下面有 HTML 代码
<mat-form-field>
<input matInput type="text" [matAutocomplete]="countryAutoComplete"
formControlName="country" [disabled]="true">
<mat-autocomplete #countryAutoComplete="matAutocomplete" [displayWith]="displayFn">
<mat-option *ngFor="let item of filterOncountryList | async" [value]="item">
{{item.CountryName}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
问题是我在ngOnInit()
this.vendorDetails.controls['country'].disable();
默认情况下,我设置如下所示
vendorDetails = new FormGroup({
accountGroupName: new FormControl(Validators.required),
country: new FormControl({ CountryName: "India", CountryCode: "IN" }, Validators.required),
});
在提交表单时,我需要获取所有值,但此行出现错误。
if(this.vendorDetails.value.country.CountryCode == null || this.vendorDetails.value.country.CountryCode == ''){
this.setCountryError = setErrors.errormsg.countryErrorMsg;
this.vendorDetails.controls['country'].setErrors({ 'incorrect': true });
regError = true;
}
错误TypeError:无法读取未定义的属性“ CountryCode”
在调试时,我看不到国家/地区表单控件。