Angularjs, existing javascript object shows null, how?

I have a situation where I console.log an object that it shows as null but at the same time has some properties in it.

I fit this tutorial or in one word:

.factory('Auth', function ($http, $q, $firebase, FBURL, $location, $firebaseSimpleLogin, $rootScope) {
        var ref = new Firebase(FBURL);
        var auth = $firebaseSimpleLogin(ref);
        console.log(auth);
        var Auth = {
            signedIn: function () {
                return auth.user !== null;
            },
            login: function (user) {
                return auth.$login('password', user);
            }
        };

        $rootScope.signedIn = function () {
            return Auth.signedIn();
        };

        return Auth;
    });

      

and I get the following:

enter image description here

in this case after authentication console.log(Auth.signedIn());

return false

, because the object in the log shows as null, but when I open for view I can see the properties

what is it?

+3


source to share


1 answer


The function $AngularFire.$fireBaseSimpleLogin.login

returns. Its asynchronous. Patrick Evan's comment for sure. By the time you look at the object in the console, it now has information in it.

If you keep following the tutorial, the controller will wrap a function at the end login

to handle the promise correctly.



Note. , so the function Auth.login

you wrote just returns the value of another function call. Basically you create an interface to abstract the login details from the controller (or other services) later. The controller doesn't really need to know what service you are using to log in, just that the function login

returns a promise that it can do something later.

+2


source







All Articles