0

I'm trying to redirect to other page on angular after posting data to API, I typed this code:

$scope.Proceed = function () {
        DataService.InsertPerson($scope.p)
        .then(function success(data) {
            $scope.p.ID = data.data;
            var url = "http://" + $window.location.host + "/#/show/person/";
            $window.location.href =  url + data.data; //adding ID to url
        });
    };

the page redirected correctly , But Angular Throws an error:

Error: $rootScope:infdig Infinite $digest Loop

I tryed $location but same results.

thank you for your time

1
  • which router are you using? Commented Nov 20, 2016 at 11:39

1 Answer 1

1

Instead of doing a redirection with $window.location.href you can use AngularJS $location to change the URL and add it to the history stack:

$location.url('/show/person/' +  data.data);

Or:

$location.path('/show/person/' +  data.data);

Both methods are getter / setter:

  • $location.url returns the entire URL after the slash, including search string parameters and change path, search and hash, when called with parameter and return $location.
  • $location.path returns the part of the URL after the slash not including search string parameters and change path when called with parameter and return $location.
Sign up to request clarification or add additional context in comments.

6 Comments

After changing the code and using $location, Angular route to default page.
Have to check the new url is well formed and exists in your routes, and also check that the data.data returned from the success function is a valid valid value..
See that I have used /#/show/person/ similar to you.. Try with: $location.url('/show/person/' + data.data);
Have to check the new url is well formed and exists in your routes yes the same url is redirect with '$window.location.href' , and I testing using hard coded value '$location.url('/#/show/person/' + "1");'
The problem was solved after using $location.path('/show/person/' + data.data) WITHOUT #
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.