title: How do I redirect after ajax request in angularjs?
body: <p>I am using angularjs and nodejs for my project. Now after I do my authentication using background call. Now after I receive my successful authentication, how do I redirect the user to dashboard? Here is my login div:</p>
  
  <pre><code>  &lt;div ng-controller="loginCtrl" class="control"&gt;
      &lt;form role="form" name="docRegForm" ng-submit="login()" enctype="multipart/form-data" class="col-xs-11 div-center"&gt;
        &lt;div class="input-group"&gt;
          &lt;input id="exampleInputEmail1" type="text" placeholder="Username" ng-model="user.username" class="form-control"/&gt;
        &lt;/div&gt;
        &lt;div class="input-group"&gt;
          &lt;input id="exampleInputPassword1" type="password" placeholder="Password" ng-model="user.password" class="form-control"/&gt;
        &lt;/div&gt;
        &lt;div class="col-xs-12 div-center"&gt;
          &lt;button type="submit" class="btn btn-danger full-width"&gt;LOGIN&lt;/button&gt;
  </code></pre>
  
  <p>And my angular controller is:</p>
  
  <pre><code>app.controller('loginCtrl', function ($scope, $http, $window) {
    $scope.message = '';
  
    $scope.login = function () {
      $http
        .post('/authenticate', $scope.user)
        .success(function (data, status, headers, config) {
          $window.localStorage.nimbusToken = data.token;
          console.log($window.localStorage.token);
          $scope.message = 'Welcome';  
          };
          alerts[data.status];
        })
        .error(function (data, status, headers, config) {
          // Erase the token if the user fails to log in
          alert("failure");
          delete $window.localStorage.token;
          // Handle login errors here
          $scope.message = 'Error: Invalid user or password';
        });
    };
  });
  </code></pre>
  
  <p>Now after the login, I have to redirect to dashboard or to relogin, if failed login. How do I do that?</p>