javascript – In Angular, how to redirect with $location.path as $ success callback-ThrowExceptions

Exception or error:

I am attempting to make a simple authentication service by sending a Post to a php file, I need it to load the home page partial on my ng-view when its successful.

This is what I tried :

function loginCtrl($scope, $http, $location){

Results in my url changing but ng-view not updating. It updates when I manually refresh the page.

(routes have been configured properly at the $routeProvider, I have tested redirecting this with a standalone function not as a callback and it works )

I have also tried defining $location.path('/home') as a function and then calling it on the callback it still doesn’t work.

I did some research and found some articles stating this happens when using another third party plugin, I am only loading angular.js

Any insights or pointers to some study material will be great

How to solve:

Here is the changeLocation example from this article

//be sure to inject $scope and $location
var changeLocation = function(url, forceReload) {
  $scope = $scope || angular.element(document).scope();
  if(forceReload || $scope.$$phase) {
    window.location = url;
  else {
    //only use this if you want to replace the history stack

    //this this if you want to change the URL and add it to the history stack


There is simple answer in the official guide:

What does it not do?

It does not cause a full page reload when the browser URL is changed.
To reload the page after changing the URL, use the lower-level API,



I am doing the below for page redirection(from login to home page). I have to pass the user object also to the home page. so, i am using windows localstorage.

        method : 'POST',
        headers: {
            'Content-Type': 'application/json'
        data: userData
        $scope.updLoginDetails = loginDetails;
        if($scope.updLoginDetails.successful == true)
                loginDetails.custId = $scope.updLoginDetails.customerDetails.cust_ID;
                loginDetails.userName = $scope.updLoginDetails.customerDetails.cust_NM;
                window.localStorage.setItem("loginDetails", JSON.stringify(loginDetails));
        alert('No access available.');

        alert('No access available.');      

And it worked for me.


Instead of using success, I change it to then and it works.

here is the code:

lgrg.controller('login', function($scope, $window, $http) {
    $scope.loginUser = {};

    $scope.submitForm = function() {
        $scope.errorInfo = null

            method  : 'POST',
            url     : '/login',
            headers : {'Content-Type': 'application/json'}
            data: $scope.loginUser
        }).then(function(data) {
            if (!data.status) {
                $scope.errorInfo =
            } else {
                //page jump
                $window.location.href = '/admin';


Use : $window.location.href = ‘/Home.html’;


it’s very easy code .. but hard to fined..

detailsApp.controller("SchoolCtrl", function ($scope, $location) { 
      $scope.addSchool = function () {

        location.href='/ManageSchool/TeacherProfile?ID=' + $scope.TeacherID;

Leave a Reply

Your email address will not be published. Required fields are marked *