I have made form with serval validation who work well. I want use Custom validation but I can’t find how can I make server call. I have search on many documentation and blog article…
Alright… I tried several things… since I may facing this issue as well in future… Yes, its true you can’t inject any other parameter into the validation method, as it only take ‘Control’ object. And I’m not sure if it will work since the validation rules expected result in the form of { [s: string]: boolean }. I never knew it could receive promise as result. Never try it though.
So, you can’t bring your service in here. But, for me, validation is nothing but a simple kind of utilities of some sort. It it’s me, I would make http request directly within the validator.
I was cheating a bit. To be honest, I never use angular-own http library. Instead, I’m using ‘Axios’. Here’s a sample of the code. Never get the chance to verify whether it will work or not. But the typescript compiler never throw me any error. Not sure if it will throw error on runtime instead. I’m currently upgrading my form to the new beta11. Maybe I can give it a try later on.