2014-12-04 33 views
0

我只能從第1頁轉到第2頁,但無法從第2頁回到第1

演示http://codepen.io/anon/pen/qEOJBp

我不知道爲什麼?該代碼看起來完美無瑕,我:

<ion-nav-view name="home"></ion-nav-view> 
<ion-nav-view name="threadContent"></ion-nav-view> 

<script type="text/ng-template" id="home.html"> 
    <ion-view name="home"> 
    <ion-content> 
     <h2>Home Page</h2> 
     <p>Here is the main route for the app.</p> 
     <a href="#/threadContent">GO</a> 
    </ion-content> 
    </ion-view> 
</script> 

<script type="text/ng-template" id="threadContent.html"> 
    <ion-view name="threadContent" title="Thread Content"> 
    <ion-content> 
    <a href="#/home">Back</a> 
     <h2>Using the app</h2> 
     <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis architecto hic officia quasi excepturi sequi deleniti maiores consectetur veritatis sint?</p> 
    </ion-content> 
    </ion-view> 
</script> 

回答

0
$rootScope.$on('$stateChangeSuccess', function (event, to, toParams, from, fromParams) { 
    $rootScope.$previousState = from; 
    $rootScope.$previousStateParams = fromParams; 
}); 

在項目中,我使用ui.router,但主要思路是:抓住 改變狀態的事件和數據保存到根範圍。你將永遠有能力回到以前的狀態。