W
W
WebDev2015-04-15 13:08:13
Angular
WebDev, 2015-04-15 13:08:13

How to set a function in Angular to change the url?

You need to check the token when changing the url, Google suggests this:

.run(function($rootScope) {
    $rootScope.$on('$routeChangeSuccess', function () {
        if (!$localStorage.token) {
            console.log('redirect here');
        }
    })
});

I call this method in app.config.
The run method works correctly, but I don't get into routeChangeSuccess. Where is the mistake?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Philip Balasanov, 2015-04-15
@philipb

need ui router

D
Dmitry Dedukhin, 2015-04-15
@Demetros

Did you add dependencies to your ngRoute module?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question