각도/타이프 스크립트의 사용자 정의 유효성 검사기 작업 중입니다. 당신이 볼 수 있듯이, 내가 DI하여 다른 구성 요소에서 getNewRestToPay() 메서드를 호출하려고사용자 정의 유효성 검사기 각도 의존성 주입
export class Validator {
constructor(private sharedDocument: SharedDocument) { }
static amountIsValid(control: FormControl): any {
return new Promise(resolve => {
setTimeout(() => {
console.log(Number.parseInt(control.value), "control.value");
if (Number.parseInt(control.value) >= this.sharedDocument.getNewRestToPay()) {
resolve({
"error !": true
});
}
else {
resolve(null);
}
}, 50);
});
}
}
: 이것은 내 클래스입니다. 하지만이 구성 요소는 정적 일 수 있습니다. 그것은 나를 오류 표시 : 'sharedDocument'속성 'Validator'유형에 존재하지 않습니다.
정적 구성 요소를 사용하는 경우 구성 요소 측의 메서드를 정적 메서드로 변경해야합니다. 이 경우, 나는 내가 필요로하는 나의 재산을 돌려 줄 수 없다.
@Injectable()
export class SharedDocument {
//some code
getNewRestToPay() :any{
return this.restCaisse;
}
}
이 문제를 어떻게 해결할 수 있습니까?
'sharedImage : sharedDocument : SharedDocument'를 매개 변수로'amountIsValid '에 전달하지 않으시겠습니까? – Saravana