2017-07-30 43 views
1

我是一個有角度的新手,請耐心等待。在訪問「詳細信息」頁面時在「列表」頁面上持久保存數據

我一直在試圖做一段時間,並不知道如何去做。

我有三個(1抽象父)的狀態,像這樣:

.state('recipes', { 
    url: '/recipes', 
    abstract: true, 
    template: '<ui-view/>' 
    }) 
    .state('recipes.listing', { 
    url: '/listing', 
    templateUrl: '/modules/recipes/client/views/recipes.listing.html', 
    controller: 'RecipesController', 
    controllerAs: 'vm', 
    data: { 
     pageTitle: 'Recipes' 
    } 
    }) 
    .state('recipes.details', { 
    url: '/details', 
    templateUrl: '/modules/recipes/client/views/recipes.details.html', 
    controller: 'RecipesDetailsController', 
    controllerAs: 'vm' 
    }); 

從列表頁面,用戶,他們可以從選擇列表..當從列表中選擇他們訪問的詳細信息頁面通過$ state.go()。現在,當他們按下「後退」按鈕時,他們會回到列表頁面,但他們查詢的所有數據現在都消失了。我能想到的唯一方法就是將頁面轉換爲視圖並將它們插入到1個狀態,然後顯示/隱藏它們,但是我覺得這不是Angular方式。

在此先感謝。

+0

使用服務來存儲任何需要複製視圖時用戶返回 – charlietfl

+0

@charlietfl這是另一種解決方案,我已經遇到。我感覺這可能是另一條好路線。我不知道爲什麼,但我希望有一個更優雅的'角'解決方案 –

+0

這是角度的方式。當您離開視圖時,控制器實例不見了,但服務是單例 – charlietfl

回答

3

我建議以RESTfull方式使用路由。例商家資訊頁面的路徑可能是:

.state('recipes', { 
    url: '/recipes', 
    templateUrl: '/modules/recipes/client/views/recipes.listing.html', 
    controller: 'RecipesController', 
    controllerAs: 'vm', 
    data: { 
     pageTitle: 'Recipes' 
    } 
}) 

而對於細節的路線:

.state('recipes.details', { 
    url: '/recipes/:recipeID/details', 
    templateUrl: '/modules/recipes/client/views/recipe.details.html', 
    controller: 'RecipesDetailsController', 
    controllerAs: 'vm' 
    }); 

而且你的房源頁面,您可以添加基於ID鏈接,以達到每個項目的詳細信息頁面。如果您使用的桌子,你的表身應被看作是這樣的:

<tbody> 
    <tr ng-repeat= "recipe in recipes"> 
     <td><a ng-href="#!/recipes/{{::recipe._id}}/details"></a></td> 
    </tr> 
</tbody> 
+0

我不明白這是如何解決問題的。這看起來像我們只是重新組織頁面。我不確定這是否解決了我提出的問題 –

+0

遇到從列表中選擇一個項目時,它會進入該項目的詳細信息頁面,因爲可以爲所選項目唯一構建路線,而不會在一個狀態中隱藏其他項目。 (我認爲更有角度的方式) –

相關問題