Dennis Kiesel Dennis Kiesel - 5 months ago 47
AngularJS Question

Redirect to a different page after POST using Angular

After searching and not coming up with a solution I am posting this code snippet for some help.

$scope.createAddress = function () {
$http({
method: 'POST',
url: '/addressBook/api/Person',
data: $scope.person,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}).success(function (data) {
$location.path('/addressBook');
});
}


After successfully posting I would like to redirect to a different page. $location.path is not accomplishing this. I have tried $scope.apply() as some others have had success with that. Am I missing something or not understanding what $location is used for? The code is being hit.

Answer

There should be something listening on that path change, like a $routeProvider. Is that the case?

If you need a full page reload to that other (server-side) route you might try $window.location.href.