Kiran Kumar Kiran Kumar - 8 months ago 31
AngularJS Question

Redirect to new Page in AngularJS using $location

I am testing with the following AngularJS $location. I don't what's the problem with this. Just want to check if the redirection is working or not:


<body data-ng-controller="MainCtrl">
Hello {{name}}!
<button ng-click='go()'>Go</button>

AngularJS code

var app = angular.module('location', []);
app.controller('MainCtrl', function($scope,$routeParams, $location) {
$ = 'World';
$scope.go = function() {
$location.absUrl() = '';


$location won't help you with external URLs, use the $window service instead:

$window.location.href = '';

Note that you could use the window object, but it is bad practice since $window is easily mockable whereas window is not.