0

I need to understand how come the assignment of vm.Info var does not work properly. Sorry for the bad question.

 vm.getUser = function(email) {
             vm.Info = ''  

                authentication
                    .avvocatoByEmail(email)
                    .error(function(err){
                        return null;
                    }).success(function(data){
                        vm.data = { user : data };

                        vm.Info = $crypto.encrypt(vm.data.user[0].id + "." + vm.data.user[0].email, 'myKey');
                        console.log("Here ok: " + vm.Info);

                    });

                console.log("Here blank: " + vm.Info);
            }
Giuseppe Canto
  • 159
  • 1
  • 1
  • 14

1 Answers1

1

Because ajax call is asynchronous, and as a result, your second console.log (which isnt working) will get executed first; And once success event of ajax call is fired, the first console.log will work where you are assigning data to that variable.

Developer
  • 6,240
  • 3
  • 18
  • 24