V
V
Vladimir2017-07-04 13:29:51
MySQL
Vladimir, 2017-07-04 13:29:51

How to prevent a route change on $routeChangeStart so that $routeChangeError will work after?

There is a bunch of events

$rootScope.$on('$routeChangeStart', (event, next, current) => {
      console.log('current', current, next);
      event.preventDefault();
    });

    $rootScope.$on('$routeChangeError', (event, current, prevoius, reason) => {
      console.log('err', [event, current, prevoius, reason]);
    });

The routeChangeStart event fires and event.preventDefault() prevents the path from changing, but the routeChangeError event does not fire after that.
It is necessary to prohibit the path change so that the routeChangeError event fires and I can pass the reason why I forbade the path change to it.
https://docs.angularjs.org/api/ngRoute/service/$route

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
Hanneman, 2018-12-14
@dimastik1986

The task is still not entirely clear (if there are some "buts" there), but it is done like this:

select distinct group_id from (
    select group_id from place
    union 
    select group_id from promo
) x;

N
Nicholas, 2017-07-04
@healqq

After preventDefault, nothing should work.
routeChangeError occurs when one of the resolve promises is rejected, in fact it is better to hang up the check in state.resolve, and not in $routeChangeStart.
In general, with the release of 1.x UI-router, everything has become much cooler in this regard. Including there you can do what you want, namely transition hooks .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question