【发布时间】:2015-03-12 21:45:04
【问题描述】:
承诺解决后,我需要从我的工厂更新变量notifications。
我们的想法是这样称呼它:
InboxNotificationFactory.notifications
这将返回 0,然后当 promise 被解决时,它将更新为其他值,而无需在我的控制器中使用 .then()。
inboxApp.factory('InboxNotificationFactory', function (inboxHttpService) {
getNotifications();
return {
notifications: 0
};
function getNotifications() {
inboxHttpService.totalUnreadMessages().then(function(response) {
//ERROR RIGHT HERE
this.notifications = response.data;
});
}
});
【问题讨论】: