Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$locationChangeStart event triggers too late

I have the next problem.

I have different behaviours of <a> elements. I have a controller which handle 2 events:

$scope.$on("$destroy", function () {
    console.log("$destroy");
});

$scope.$on("$locationChangeStart", function () {
    console.log("$locationChangeStart");
});

Sometimes $locationChangeStart event fired first, but sometimes $destroy event fired first.

I need to prevent changing page, so I need $locationChangeStart to be fired first.

Please, someone has any thoughts, why different <a> have different sequence of events?

UPD I use the same <a> element in different parts of page

<a href="#/overview">test</a>
like image 970
Gleb Avatar asked Jan 27 '26 17:01

Gleb


1 Answers

If you want to prevent changing page it doesn't matter which one is launch first.

In your $locationChangeStart add the event object:

$scope.$on("$locationChangeStart", function (event) {
    event.preventDefault(); // will prevent the location change
});
like image 50
IsraGab Avatar answered Jan 30 '26 06:01

IsraGab



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!