Validators with remote server


#1

Hi!
In AngujarJS (not ionic) when I validate if an email exists in the database, I used the remote property in the validation:

         validator = $("#formRegister").validate({
            rules: {
                email: {
                    required: true,
                    email: true,
                    remote: Config.coreurl+'/user/exists'
                }
            },
            //For custom messages
            messages: {                 
                email:{
                    required: "Ingrese su e-mail",
                    email: "El e-mail es incorrecto",
                    remote: jQuery.validator.format("{0} ya esta siendo usado")
                },
            }
         });

Now in Ionic 2, the validation is harder becouse I couldn’t find any documentation how to do remote validation.
Some forums tell that I have to create a Custom Validator and use Http, creating a Promise and returning It when the result is resolved. BUT, I can’t inject the Http in a Validator. I try to use ReflectiveInjector.resolveAndCreate but crash when I put HTTP_PROVIDERS like a provider:

let injector: Injector  = ReflectiveInjector.resolveAndCreate([Http, HTTP_PROVIDERS]);
let http: Http = injector.get(Http); 

The message was: only instances of Provider and Type are allowed

Some posts is related to Angular2 only, not Ionic2.

No forum could helpme with that. I hope the official forum can help me!
Thanks.

Your system information:

Cordova CLI: 6.3.1
Gulp version: CLI version 3.9.0
Gulp local: Local version 3.9.0
Ionic Framework Version: 2.0.0-rc.3
Ionic CLI Version: 2.1.0
Ionic App Lib Version: 2.1.0-beta.1
OS: Distributor ID: Ubuntu Description: Ubuntu 16.04.1 LTS
Node Version: v6.3.1