Redirect using AngularJS

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?

With an example of the not working code 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.

Assuming you're not using html5 routing, try $location.path("route"). This will redirect your browser to #/route which might be what you want.

If you need to redirect out of your angular application use $window.location. That was my case; hopefully someone will find it useful.

It is hardy to say without knowing your code. My best guess is that "oncahnge" event is not firing if you change textbox value from javascript code. There are two ways, one is to call onchange by your self or to wait that textbox lose focus

Check this question, same issue different framework Call Javascript onchange event by programatically changing textbox value

just use window.location = "your_url"