user11001
user11001

Reputation: 372

href and ng-click in angularjs

I have this line at the code:

<a href="/blabla/topQues.html#{{m}}"data-ng-click="$event.preventDefault(); getQues()"></a>

The function getQues() pars the URL and do somthing, But the getQues() call befre the URL really changed.

What can i do to solve it?

Upvotes: 0

Views: 477

Answers (2)

adib.mosharrof
adib.mosharrof

Reputation: 1634

Change your html a bit, pass the URL as a parameter to your getQues() function. Do

Do the parsing and other work in your function, then go to the desired url using $location.path("url")

If you want to keep the href attribute in the html tag, use ng-href instead of href

https://docs.angularjs.org/api/ng/directive/ngHref

<a ng-href="/blabla/topQues.html#{{m}}" data-ng-click="$event.preventDefault(); getQues()"></a>

Upvotes: 0

MBN
MBN

Reputation: 1006

Use this:

$scope.$on('$routeChangeSuccess', function () {

    var url = $location.path();
    $scope.getQues(); // you can pass url to this function

});

Upvotes: 1

Related Questions