Well. Is the promise isn’t returned, there’s nothing showing in the template, not even [object Object].
The nested item runs and the nickname is correct not matter whether the promise is returned. But the value isn’t showing in the template.
If a fixed value is returned instead of a promise, that value is displayed correctly.
From:
Martin Feckie
Sent:
11/24/2014 12:58 PM
To:
hellomao@outlook.com
Subject:
[Ember.JS] Return a promise in a computed properties in a controller
mfeckie
November 24
From first glance it looks like the use of two returns would be your problem.
return this.store.find('user', this.model.get('user')).then(function(user) {
When this promise is returned, the nested item has not yet resolved. Does that make sense?
To respond, reply to this email or visit
http://discuss.emberjs.com/t/return-a-promise-in-a-computed-properties-in-a-controller/6783/2 in your browser.
Previous Replies
kceiw
November 24
Hi,
I have troubles getting a value in a computed properties in a controller. It seems to me that a computed property doesn't work well with a promise. But I'm not sure whether I do something stupidly wrong. Here is the computed
property in a controller
userNickname: function() {
return this.store.find('user', this.model.get('user')).then(function(user) {
Ember.debug('****user nickname: ' + user.get('nickname'));
return user.get('nickname');
});
}.property('model'),
And in the template I use
{{userNickname}}
The promise returns correct value. I see from the console that the right nickname is logged. But the page only displays [object Object]
Am I missing anything here? What's the best way to load piece of data only when it's needed?
To respond, reply to this email or visit
http://discuss.emberjs.com/t/return-a-promise-in-a-computed-properties-in-a-controller/6783/2 in your browser.
To unsubscribe from these emails, visit your
user preferences.