title: How to do automatic login in angular js?
body: <p>i have a login screen and i am doing login by using some hard cord data.</p>
  
  <pre><code>angular.module('starter.controllers', [])
  
  
  
  
       .controller('AppCtrl', function($scope, $rootScope, $window,             $ionicModal, $timeout, authService, $state, $http, $ionicLoading, $location) {
           //$window.location.reload();
  
       $scope.loginSubmitted = false;
      $scope.myflag = false;
       $scope.User = {};
      $scope.toast = function() {
         $ionicLoading.show({
    template: 'wrong credentials'
  });
  $timeout(function() {
    $ionicLoading.hide();
  }, 1000);
          }
           $scope.footerflag = true;
             $scope.hidefooter = function() {
            $timeout(function() {
  $scope.footerflag = false;
           },1)
          }
               $scope.showfooter = function() {
     $timeout(function() {
      $scope.footerflag = true;
    },1)
               }
  
  
           $scope.doLogin = function() {
  console.log("trying login");
  
  //  // var res = $http.post('http://login.com/postLogin', $scope.user);
  //  authService.postdetails($scope.User).success(function(data, status, headers, config) {
  //   $scope.message = data;
  //   console.log("succesfn");
  //   console.log(status);
  //
  // })
  //  .error(function(data, status, headers, config) {
  //   alert("failure message: " + JSON.stringify({
  //     data: data
  //   }));
  //   console.log(fail);
  // });
  $scope.loginSubmitted = true;
  $scope.loginstatus = 0;
  authService.GetByUsername().success(function(data) {
    $scope.UserData = data;
    // console.log($scope.UserData);
    for (var i = 0; i &lt; $scope.UserData.length; i++) {
      if ($scope.UserData[i].UserName == $scope.User.UserName &amp;&amp; $scope.UserData[i].Password == $scope.User.Password) {
        authService.currentuser = $scope.User.UserName;
        //console.log(authService.currentuser);
        $scope.loginstatus = 1;
        break;
      }
    }
    if ($scope.loginstatus == 1) {
  
      // var lastVal = $cookieStore.get($scope.User.UserName);
      // console.log(lastVal);
      //$location.path('/app/playlists');
      $scope.loginstatus = 0;
      $state.go('app.playlists', null, {
        reload: true
      });
    } else {
      console.log('wrong credentials');
      $scope.toast();
    }
  
  }).error(function(err) {
    console.log(err);
  });
  
  
          }
  
  
  
         });
  </code></pre>
  
  <p>So i want to enable automatic login, till the user clicks logout button. How it can be done?
  I'm simply redirecting to another page when username and password matches.</p>