I need to update the variable notifications from my factory after the promise is resolved.
The idea is to to call it like this:
InboxNotificationFactory.notifications
and this will return 0, and then when the promise is resolved it will update to some other value without the need to used .then() inside my controller.
inboxApp.factory('InboxNotificationFactory', function (inboxHttpService) {
getNotifications();
return {
notifications: 0
};
function getNotifications() {
inboxHttpService.totalUnreadMessages().then(function(response) {
//ERROR RIGHT HERE
this.notifications = response.data;
});
}
});