$window.location.href NOT WORKING in AngularJS

Varun Nair picture Varun Nair · Dec 1, 2015 · Viewed 34.3k times · Source

I'm building a basic AngularJS Login page and the $window.location.href did not re-direct the page to a new html in my system, hosted by WAMP. I even tried re-directing it to google. Nothing happens. I tried all the available solutions here and nothing seems to work. Any solutions ?

JS followed by HTML

Answer

Alexandre picture Alexandre · Dec 1, 2015

In angular js you can use $location. Inject it in your controller :

app.controller('MainCtrl', function($scope, $location) { ... }

And if you want to redirect to google use its url() method :

$location.url('http://google.fr');

you can also use path() method for relative url :

$location.path('home'); // will redirect you to 'yourDomain.xx/home'

https://docs.angularjs.org/api/ng/service/$location