我有一个验证器,作为一个使用类型,我需要测试item是否在数组中。太好了,我可以在输入中获取值但是如何传递数组?
mylist = ['a','b']
constructor(private fb: FormBuilder){
this.myForm = this.fb.group({
slug: ['',[Validators.required,this.validateSlug]],
description: ['']
})
}
validateSlug(control: FormGroup) {
var valid:any;
//THIS IF control.value IN mylist
console.log('dude',control.value);
valid=true;
return valid ? null : { validateSlug: true };
}
我似乎无法访问validateSlug中的任何内容。
slug: ['',[Validators.required,this.validateSlug(this.items)]],
validateSlug(param1) => (control: FormGroup) {
var valid:any;
console.log(control.value);
//let fx = this.items.filter(x => x === control.value)[0];
valid=true;
return valid ? null : { validateSlug: true };
}
答案 0 :(得分:0)
getSlugValidator(param1, param2) =>
(control: FormGroup) {
// param1, param2 are available here
var valid:any;
//THIS IF control.value IN mylist
console.log('dude',control.value);
valid=true;
return valid ? null : { validateSlug: true };
};
slug: ['',[Validators.required,this.validateSlug(p1, p2)]],