2015-11-08 56 views
0

我查詢數據庫和檢索所有屬於圖像登錄的用戶,這裏是uploadController代碼:

UserImage.get($scope.user_id) 
    .success(function(data) { 

     $scope.userArray = data; 

     $location.path('/display'); 
    }); 

我可以控制檯日誌數據的價值它是(頭文件):

0: Object 
__v: 0 
_id: "563bd07c7a49a7ac9ae1c513" 
date: "2015-11-05T21:56:12.312Z" 
gallery: "first gallery" 
name: "1b0f6d56-9ed6-4412-a0d6-897a25fb3a84-460x360.jpeg" 
user: "563bd0527a49a7ac9ae1c512" 

所以現在我測試的目標視圖(display.html)可以收到$ scope.data:

<<div>{{userArray[0].name}}</div> 

$ scope.userArray不適用於display.html。 我測試了$在掠奪者的範圍,它的工作正常: http://plnkr.co/edit/q5XXnfl3JxkRdG0jLyps?p=preview 所以我有點難住。

+0

什麼是錯誤? – Sajeetharan

+0

你還沒有包含你的路由,但它看起來你添加了數據到你的範圍,然後改變路徑,我假設一個新的路線與不同的範圍? – Tristan

+0

@Tristan - 實際上是同一個控制器 - 沒有改變。我嘗試交換它,以便在$ scope給出數據之前更改路徑,但沒有區別。 – meanstacky

回答

1

首先您應該使用「.then」而不是「.success」來使用承諾系統。 If you want to know more about it

我認爲你的問題也與$location.path('/display');有關,你要求你的應用程序在你得到答案時立即改變位置,所以它可能會加載另一個控制器並停止使用當前的控制器。

+0

是的,我忘了成功和錯誤被棄用。由於我已經在$ scope.userArray中獲得了正確的數據,我認爲你是對的,$ location.path正在搞砸了。我在顯示視圖中使用了相同的控制器,但是您能否建議替代$ location.path。謝謝 – meanstacky