2016-07-05 47 views
1

我嘗試了幾種方法,但$ state.go()不刷新我的頁面。這裏是我的控制器。所有進程都能正常工作,但我無法使用$ state.go()函數重新加載瀏覽頁面。

angular.module( 'kawaadi.controllers',[])

.controller('AppCtrl', function ($scope, Service, $ionicLoading, $ionicModal, $ionicPopup, $timeout, $state, $http,$location) { 

    $scope.loginData = {}; 

    $ionicModal.fromTemplateUrl('templates/login.html', { 
     scope: $scope 
    }).then(function (modal) { 
      $scope.modal = modal; 
     }); 

    $scope.closeLogin = function() { 
     $scope.modal.hide(); 
    }; 

    $scope.login = function() { 
     $scope.modal.show(); 
    }; 
    $scope.logout = function() { 
     localStorage.setItem("token", ""); 
     $state.go('login'); 
    }; 

    $scope.statusData = function (pid, uid, status) { 
     $ionicLoading.show({ 
      template: 'Processing...' 
     }); 
     Service.change_status(pid, uid, status, $http).success(function (data) { 
      if (data.status === 'success' && data.notification_status === 'success') { 
       $ionicLoading.hide(); 
       var alertPopup = $ionicPopup.alert({ 
        title: 'Success!', 
        template: 'Successfully changed and notification has been send!' 
       }); 
      } else if (data.status === 'success' && data.notification_status === 'failure') { 
       $ionicLoading.hide(); 
       var alertPopup = $ionicPopup.alert({ 
        title: 'Success!', 
        template: 'Successfully changed but failed to send notification!!' 
       }); 
      } 
      alertPopup.then(function (res) { 
       if (res == true) { 
        $state.go('app.browse'); 
       } 
      }); 
     }).error(function (data) { 
       var alertPopup = $ionicPopup.alert({ 
        title: 'Process failed!', 
        template: 'Some thing went wrong!' 
       }); 
      }); 

    } 
}) 

,這裏是我的網址路由器

.config(function ($stateProvider, $urlRouterProvider) { 
     $stateProvider 

       .state('login', { 
        url: '/login', 
        templateUrl: 'templates/auth.html', 
        controller: 'LoginCtrl' 
       }) 
       .state('app', { 
        url: '/app', 
        templateUrl: 'templates/menu.html', 
        controller: 'AppCtrl' 
       }) 

       .state('app.search', { 
        url: '/search', 
        views: { 
         'menuContent': { 
          templateUrl: 'templates/search.html' 
         } 
        } 
       }) 

       .state('app.browse', { 
        url: '/browse', 
        views: { 
         'menuContent': { 
          templateUrl: 'templates/browse.html', 
          controller: 'pickupCtrl' 
         } 
        } 
       }) 
       .state('app.playlists', { 
        url: '/playlists', 
        views: { 
         'menuContent': { 
          templateUrl: 'templates/playlists.html', 
          controller: 'PlaylistsCtrl' 
         } 
        } 
       }) 

       .state('app.single', { 
        url: '/playlists/:playlistId', 
        views: { 
         'menuContent': { 
          templateUrl: 'templates/playlist.html', 
          controller: 'PlaylistCtrl' 
         } 
        } 
       }); 
    }); 

請指引我。在此先感謝

+0

請修改您的所有狀態爲'.STATE( 'emailConfirmation',{ 緩存:假的, URL: 「/ emailConfirmation」, templateUrl: 「應用程序/會話/ emailConfirmation.html」, 控制器:' EmailConfirmationCtrl' })'並重新加載當前頁面,請使用這些命令'$ state.transitionTo($ state.current,$ stateParams,{reload:true,inherit:false,notify:true});' –

+0

Thanks anil that現在工作正常。非常感謝 –

+0

我會更新我的答案,請接受它 –

回答

1

請修改您的所有國家作爲

.state('emailConfirmation',{ 
    cache: false, 
    url:"/emailConfirmation", 
    templateUrl:"app/session/emailConfirmation.html", 
    controller: 'EmailConfirmationCtrl' 
    }) 

,並重新加載當前頁請使用以下命令

$state.transitionTo($state.current, $stateParams, { 

     reload: true, 
     inherit: false, 
     notify: true 
}); 
0

如果要強制加載當前的狀態,那麼你可能需要使用$state.go($state.current.name, $state.params, {reload: true})提到here

+0

對不起,它也沒有工作,任何方式,謝謝你 –

0

只添加你離子視圖標籤下面

<ion-view cache-view="false">