你在胡乱使用
formControl
. 创建自定义时
FormControl
API
表单控制):
// for single validator
customControl = new FormControl('value', Validators.maxLength(5));
// for multiple validators(with Validators.compose)
customControl = new FormControl('value', Validators.compose([Validators.minLength(4), Validators.required]));
// or(without Validators.compose)
customControl = new FormControl('value', Validators.compose([Validators.minLength(4), Validators.required]));
将formGroup代码更改为以下任一方式将解决您的问题:
new FormControl()
this.imm = new FormGroup({
comune: [],
provincia: [],
comuneObj: [],
cap: [],
indirizzo: [],
civico: [],
localita: ['', Validators.compose([Validators.minLength(4), Validators.required])],
destinazioneUso: [],
destinazioneUsoAltro: [],
destinazioneUsoPrincipale: [],
destinazioneUsoSecondaria: [],
});
选项2:
更正formControl部分语法。
this.imm = new FormGroup({
comune: new FormControl(),
provincia: new FormControl(),
comuneObj: new FormControl(),
cap: new FormControl(),
indirizzo: new FormControl(),
civico: new FormControl(),
localita: new FormControl('', Validators.compose([Validators.minLength(4), Validators.required])),
destinazioneUso: new FormControl(),
destinazioneUsoAltro: new FormControl(),
destinazioneUsoPrincipale: new FormControl(),
destinazioneUsoSecondaria: new FormControl(),
});