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 w
Assuming you're not using html5 routing, try $location.path("route")
.
This will redirect your browser to #/route
which might be what you want.
It is hard to say without knowing your code. My best guess is that the onchange
event is not firing when you change your textbox value from JavaScript code.
There are two ways for this to work; the first is to call onchange
by yourself, and the second is to wait for the textbox to lose focus.
Check this question; same issue, different framework.
If you need to redirect out of your angular application use $window.location
. That was my case; hopefully someone will find it useful.
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.
Check your routing method:
if your routing state is like this
.state('app.register', {
url: '/register',
views: {
'menuContent': {
templateUrl: 'templates/register.html',
}
}
})
then you should use
$location.path("/app/register");