user1027620
user1027620

Reputation: 2785

Service inside angularjs .$on is not defined

app.run(function($rootScope, $location, $http, $state, Auth) {
    if (Auth.isLoggedIn()) { <-- WORKS FINE
        Auth.setUser(Auth.getUser());
    }

    $rootScope.$on('unauthenticated', function(response) {
        // Redirect to login page
        if (!Auth.IsLoggedIn()) { <-- Auth.IsLoggedIn is not a function
            $state.go('login');
        } else {
            alert('no access to view this page');
        }
    });

    $rootScope.$on('serverError', function(response) {
        // $rootScope.serverError = "Server Error";
    });
});

Any idea why I'm getting this 'Auth.IsLoggedIn is not a function' on line 8 but it's working fine on line 2?

Thanks!

Upvotes: 0

Views: 23

Answers (1)

Christofer Eliasson
Christofer Eliasson

Reputation: 33865

You use a capital I in your method name, the second time you call it.

Auth.isLoggedIn()

Compared to:

Auth.IsLoggedIn()

Upvotes: 1

Related Questions