在我的應用程序中,每個用戶都有一個特定的配置文件,我創建了一個服務來保存名爲currentUser
的配置文件。在用戶登錄後獲取角度用戶配置文件
我使用此配置文件的屬性來渲染我的網站標題並進行進一步的api調用。
問題是我應該在什麼時候填寫這個currentProfile
服務?
有幾個選項:
1 - 登錄後承諾解決:
authService.login(username, pass)
.then(function(response) {
userService.getProfile()
.then(function(profile){
currentUser.setProfile(profile);
$state.go('dashboard');
});
});
這種方法的主要問題是,如果用戶在這個網址/main/list
並刷新頁面, currentUser
被清空。
2 - 使用UI路由器deferIntercept
和urlRouter.sync()
和$urlRouter.listen()
像here,但這種方法的主要問題是,我的頭指令和控制器被之前(或期間)執行的事件處理程序的$locationChangeStart
和currentUser
尚未填補。
我該如何達到我所期望的效果?任何想法都會被接受!
編輯:我不想靠的localStorage或餅乾或....
登錄後填入個人資料到的localStorage或餅乾,把它抓回來後刷新。清除它註銷 –
@SaneeshB我不想使用這些存儲。 – Rachmaninoff