0

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?

2
  • Yes when event fires it happens by click you may need to use it bit different way like calling the Route inside the ng-click functioned controller buy $location.path('/blabla/topQues.html#{{m}}'); like that Commented Feb 29, 2016 at 10:41
  • The line of code you have re4turn above will call the function getQues() before changing the url because if prevent default What exactly are you trying to achieve here? Commented Feb 29, 2016 at 10:43

2 Answers 2

1

Use this:

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

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

});
Sign up to request clarification or add additional context in comments.

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.