如果我在表单验证中出错,请帮助我
customerGroupValidator: FormGroup = null;
constructor() {
var _builder = new FormBuilder();
this.customerGroupValidator = _builder.group({
EmpName: ['', [Validators.required, Validators.minLength(2), Validators.maxLength(4)]],
})
}
IsValid(): boolean{
return this.customerGroupValidator.valid;
}
Html代码
这里我得到错误,因为FormGroup需要一个FormGroup实例。即使我添加[formGroup] =" custobj.customerGroupValidator"
,请帮助我在哪里犯了错误<form [formGroup]="custobj.customerGroupValidator">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" formControlName="EmpName" [(ngModel)]="custobj.EmpName" />
<button type="submit" class="btn btn-success btn-block" [disabled]="!custobj.IsValid">Submit</button>
</form>