Execute function in ng-blur AngularJs

1

I'm trying to set up a project where a customer registers for access to the system, this registration can only be done if the client's CPF exists in the database.

I have two tables, Usuário and Beneficiário(Cliente) . The REST part is already working, however I want to check if the CPF exists as soon as the user goes to the next field, ie, he / she fills in the CPF and goes to the Password field, if the CPF does not exist I want to show some alert .

I am already able to recover the JSON with the data of the Client, however the function that I have done is running as soon as I start the system and I also have to pass a fixed CPF as a parameter.

In short: I want to call the function only when ng-blur occurs and retrieve cpf.

routeConfig:

angular.module("unimed").config(function($routeProvider){

    $routeProvider.when("/login", {
        templateUrl: "public/view/login.html",
        controller: "loginController",
        resolve: {
            usuario: function (loginAPI, $route) {

            },
            //Aqui passo o cpf 12345 como parametro
            beneficiarioFind: function(loginAPI, $route){
                return loginAPI.getBeneficiario(12345);
            }
        }   
    });

    $routeProvider.otherwise({redirectTo: "/login"});

});

LoginAPIService:

angular.module("unimed").factory("loginAPI", function ($http, config) {

    var _getUsuario = function(cpf){
        return $http.get(config.baseURL + "/UnimedWS/usuario/usuario/" +cpf);
    };

    var _saveUsuario = function(usuario){
        return  $http.post(config.baseURL +"/UnimedWS/usuario/", usuario);
    };

    var _getBeneficiario = function(cpf){
        return $http.get(config.baseURL + "/UnimedWS/beneficiario/find/" +cpf);
    };

    return {
        getUsuario: _getUsuario,
        saveUsuario: _saveUsuario,
        getBeneficiario: _getBeneficiario
    };
});

At each F5 or when I open the page the function is executed, even though I do not call it in controller and passing it to ng-blur .

Iwantedhertobecalledhere(Modalthatopensafterclickingontheregisterbutton):

    
asked by anonymous 17.09.2015 / 21:57

1 answer

1

You are calling the function in routeProvider's resolve, so it will be called when the page loads.

Create a function in the controller (not mentioned above) and call it in the ng-blur of the desired component.

    
17.09.2015 / 22:40