OK, I would try creating the validator as a lexically scoped closure variable instead of having it be a method. Something like this:
let validator = (control) => {
return this.injectedThingy.doSomething(control);
};
this.nameControl = new Control('', , validator);
Another option would be to refactor your validator into its own class, which can use DI in its constructor:
@Injectable()
class AsyncValidator {
constructor(private _svc:SomeService) {
}
validate(control:Control):Promise<ValidationResult> {
return this._svc.doSomething(control);
}
}
@Injectable()
class FormHavingPage {
constructor(fb: FormBuilder) {
fb.group({
'name': ['', , AsyncValidator]
});
}
}
You can use a class name for a validator instead of a function as long as DI can instantiate it and it has a method named validate
. Untested code, sorry for syntax errors.