Perform function in ng-Bank Angularjs

Asked

Viewed 334 times

1

I am trying to set up a project where a client makes his registration to have access in the system, this registration can only be performed if the client’s CPF exists in the database.

I have two tables, Usuário and Beneficiário(Cliente). The part REST is already working, but I want to check if the CPF exists as soon as the user goes to the next field, IE, it fills 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 Client data, but the function I did is being executed once I start the system and I also have to pass a fixed CPF as parameter.

In short: I want to call the function only when the ng-blur 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
    };
});

Every F5 or when I open the page the function is executed, even if I do not call it in controller and passing her on to the ng-blur.

inserir a descrição da imagem aqui

I wanted her to be called here (Modal that opens after clicking the sign up button): inserir a descrição da imagem aqui

1 answer

1


You are calling the function in the routeProvider solver, soon it will be called when the page loads.

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

  • That’s right, taking advantage of the question. How do I check to see if the returned request is void?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.