私は単純なカスタムバリデータを作成しようとしています。基本的に1つの変数(真偽)が真の場合、フィールドは必須でなければなりません。それで全部です。角2 - カスタムバリデータの発行
理由はわかりませんが、変数に代わって読むことができません。それは未定義です。これをどう扱うかについての手がかりは?
behalf = false;
private validateName(){
if (this.behalf && this.nameB.text != '') {
return {
invalidName : true
};
}
else{
return null;
}
}
constructor (private builder: FormBuilder){
this.title = new Control('', Validators.required);
this.name = new Control('', this.validateName);
this.type = new Control('', Validators.required);
this.desc = new Control('');
this.hideTitle = new Control('');
this.end = new Control('', Validators.required);
this.formBook = builder.group({
title: this.title,
name: this.name,
type: this.type,
desc: this.desc,
hideTitle: this.hideTitle,
end: this.end
});
}