我尝试在角度2中进行异步验证但得到this.subscribe is not a function
。
我的FormGroup是:
const form = new FormGroup({
example: new FormControl('example', [Validators.required], [CustomValidators.example]),
last: new FormControl('Drew'),
});
我的自定义异步验证
....
example (value : number) : AsyncValidatorFn {
return (control: AbstractControl): Observable< {[key:string]: boolean} > => {
return this.restService.exampleService(value)
};
exampleService以{match: true}
exampleService (value : any) {
return this._http.get(AppSettings.API_ENDPOINT + "company/findByNit/" + value )
.map(res => res.json());
}
答案 0 :(得分:1)
验证应该只分组在一个数组中。试试这个
const form = new FormGroup({
example: new FormControl('example', [Validators.required, CustomValidators.example]),
last: new FormControl('Drew'),
});