Redirect to a different page after POST using AngularJS Redirect to a different page after POST using AngularJS angularjs angularjs

Redirect to a different page after POST using AngularJS


Remember to inject the dependency to the controller:

                                                       |-- inject!angular.module('myApp.controllers', []).               vcontroller('AddressController', function ($scope, $location, $http) {  $http({    method: 'POST',    url: '/addressBook/api/Person',    data: $scope.person,    headers: {        'Content-Type': 'application/json; charset=utf-8'    }  }).success(function (data) {    $location.path('/addressBook');  });});


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.


in your controller add the $location. like thisEx: app.controller('yourController', function($scope, $location, $http, etc...)then on your $http should be like this.

$http({.... }).success(function(response) { $location.path('/your path')})

but make sure that you must add additional location to your $routeProvider Configuration. something like:

app.config(['$routeProvider',    function($routeProvider) {    $routeProvider.     when('/yournewlocation', {      templateUrl: 'yourTemplate/yourpage'   })  }])

thats it. well you know what im talking about.