Skip to content Skip to sidebar Skip to footer

Angularjs Routing: Cannot Read Property 'path' Of Undefined

I'm trying to trigger angularJS routing inside of a function in controller, but it throws back 'Uncaught TypeError: Cannot read property 'path' of undefined'. Can't really see wher

Solution 1:

Look at this code:

functiongameLost($location) {
        var check = false;
        console.log ('You lose! Your score is ')
        $location.path('/game-over');
}

Unless you invoke this function like this gameLost($location) (which I doubt) $location is going to end up as undefined in local function scope, overwriting $location service from parent closure scope.

So I think all you need to do is to remove $location paremeter from gameLost function definition:

functiongameLost() {
        var check = false;
        $location.path('/game-over');
}

Post a Comment for "Angularjs Routing: Cannot Read Property 'path' Of Undefined"