Ionut P.
Ionut P.

Reputation: 63

Redirect in AngularJs

I have the following code

$scope.insertTodo = function(){
                    TodoService.post($scope.todo);
                    $location.path("/#/");
                    }

It should run TodoService.post() (and he does fine) and after that redirect the user to /#/ location. The redirect is not working. What am i doing wrong ?

Thank you.

Upvotes: 0

Views: 34

Answers (1)

Ghulam Mohayudin
Ghulam Mohayudin

Reputation: 1113

You need to change $window.location.href like this

var app = angular.module('RedirectApp', []);
app.controller('RedirectURLCtrl', function($scope, $window) {
  $scope.RedirectToURL = function() {
    var host = $window.location.host;
    $window.location.href = "http://" + host + "/#/";
  };
});

Upvotes: 1

Related Questions