在edit.html
解決承諾值推遲對象>資源鏈
<div>timezone: {{userPreferencesCtrl.preference.response.format}}<div>
在UserPreferencesCtrl
this.preference = UserPreferencesFactory.userPreference;
在UserPreferencesFactory
基本上有兩種其餘-calls。拳頭 - 獲取所有的用戶偏好,並在其成功時調用另一個休息呼叫 - 獲得特定的用戶偏好。
var factory = this;
factory.userPreference = $q.defer();
...
UserPreferencesResource.all().$promise.then(
function(data) {
// some code
if (foundRightGuy) {
// get preference by ID
UserPreferencesResource.get({id: pref.preferenceID}).$promise.then(
function(data) {
factory.userPreference.resolve(data); // resolving the promise
}
);
}
}
);
return this; }]);
的問題是,在控制器端我看到了解決的承諾是這樣的:
{"promise":{"$$state":{"status":1,"value":{"response":{"preferenceID":2,"user_name":"name3", "format":"keyvalue"}}}}}
這不會對edit.html渲染。
如何讓它在屏幕上顯示preference.response.format
值?
UPDATE:(angularjs 1.3.x版)
如果不是$q.defer();
我把UserPreferencesResource.get({id: 2})
電話 - 那麼所有的渲染好。只是說所有變量都是好的(沒有拼寫錯誤或什麼的)。
你在我的答案中嘗試了代碼嗎?被緩存的對象的屬性是沒有$的promise。 – cbass 2014-12-02 19:31:59
剛剛嘗試過。更新了我的更新。 – ses 2014-12-02 19:36:25
你仍然沒有解開承諾。 – cbass 2014-12-02 19:37:06