JP Dolocanog
JP Dolocanog

Reputation: 451

AngularJs - My ui-sref anchor tag can't be cancelled by event.preventDefault()

I have this tag:

<a ui-sref="MyModule">My Module</a>

When I click on the link, this will be executed:

$scope.$on("$locationChangeStart", function (event) {

        if (!confirm('You have unsaved changes, continue?')) {
            event.preventDefault();
        }
    });

But still my view will switch to MyModule interface.

Upvotes: 0

Views: 79

Answers (1)

Tejinder Singh
Tejinder Singh

Reputation: 1120

try using this:-

$scope.$on("$stateChangeStart", function (event) {

        if (!confirm('You have unsaved changes, continue?')) {
            event.preventDefault();
        }
    });

You are using UI-router. which is state based.

Upvotes: 1

Related Questions