【发布时间】:2020-04-14 14:45:12
【问题描述】:
我正在尝试使用Promise 实现远程服务器验证器,但没有触发文本输入。
`app.component.html'
<form [formGroup]="myForm">
Foo: <input type="text" formControlName="foo">
<span *ngIf="!myForm.get('foo').valid">Not valid foo</span>
</form>
'app.component.ts'
ngOnInit() {
this.myForm = new FormGroup({
'foo': new FormControl(null, [Validators.required, this.validateAsync.bind(this)])
});
}
validateAsync(control: FormControl): Promise<any> | Observable<any> {
const promise = new Promise<any>((resolve) => {
//post the control.value and check for the response value: fooIsValid
if (fooIsValid)
resolve(null);
else
resolve({'FooRuleValidation': true});
});
return promise;
}
我做错了什么?我注意到它使 required 也无法正常工作。
【问题讨论】:
标签: angular angular-reactive-forms