无论如何,要获取角度材料中禁用的垫子自动完成形状控制的价值?

时间:2019-11-18 09:36:34

标签: angular angular-material angular-reactive-forms

我在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”

在调试时,我看不到国家/地区表单控件。

0 个答案:

没有答案