I'm trying to redirect to another route using:
$location.path("/route");
But for some reason it is not working. I did an auto-complete widget using jQuery-UI and I'm calling a function from the scope once the user selects an option. I debugged it and it enters the function but it is never redirected to the other route. It only changes the route when I press a key.
I think it is kind of strange but I haven't figured out how to solve this. I used
window.location = "#/route";
and it works but I want to use the path()
function.
Does anybody have any idea why this is happening?
Redirect to another page in AngularJS Here, the div element acts as the AngularJS app as well as the controller. The ng-click directive tells what to do when the button(here) is pressed. In this case, it calls the redirect() method.
The $location in AngularJS basically uses a window. location service. The $location is used to read or change the URL in the browser and it is used to reflect that URL on our page. Any change made in the URL is stored in the $location service in AngularJS.
With an example of the not-working code, it will be easy to answer this question, but with this information the best that I can think is that you are calling the $location.path outside of the AngularJS digest.
Try doing this on the directive scope.$apply(function() { $location.path("/route"); });
Don't forget to inject $location
into controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With