记录和退回视图后无法正常工作?

时间:2016-03-31 01:51:41

标签: javascript angularjs ionic-framework

下面是我的侧边栏(菜单)控制器。如果令牌存在于localstorage中并且我点击了注销,则此方法有效。

.controller('AppCtrl', function($scope, $ionicModal,$window, $timeout,$ionicHistory,$state,$rootScope) {
  var token = JSON.parse(localStorage.getItem('token'));
  if(token){
    $rootScope.loggedIn = true;
  }else{
    $rootScope.loggedIn = false;
  }

  $scope.logout = function(){
    localStorage.removeItem('token');
    $ionicHistory.clearCache().then(function() {
        $rootScope.loggedIn = false;
        $ionicHistory.clearHistory();
        $ionicHistory.nextViewOptions({ disableBack: true, historyRoot: true });
        $state.go('app.shop');
    })
  }

})

视图确实已更新,我在loggedIn视图中使用了ng-show

我的问题出在我的登录控制器上,登录后边栏没有刷新。

.controller('signupLoginCtrl', function($scope, $http, jwtHelper, $location, $ionicHistory, $state) {
$scope.doLogin = function(email, password) {
$http({
method: 'POST',
url: 'myurl.com/login',
skipAuthorization: true,
headers: {
'owner': $rootScope.secret
},
data: {
email: email,
password: password
}
}).then(function successCallback(response) {
if (response.data.success == true) {

        var tokenPayload = jwtHelper.decodeToken(response.data.msg);
        localStorage.setItem('token', JSON.stringify(tokenPayload));

        $ionicHistory.clearCache().then(function() {
          $ionicHistory.clearHistory();
          $ionicHistory.nextViewOptions({
            disableBack: true,
            historyRoot: true
          });
          $state.go('app.profile');
          $rootScope.loggedIn = true;
        })

      } else {
        alert(response.data.msg);
      }
    }, function errorCallback(response) {
      alert(response.data)
    });
  }

sidemenu视图没有得到更新,任何线索?我甚至尝试过像$state.go('app.profile',{},{reload:true})window.location = '#/app/profile'

那样的硬刷新

0 个答案:

没有答案