I have a service that contains a function, that shows a bootstrap modal. The modals result promise, when closing, is received inside the service and a promise is then resolved to the caller of the function. The service function itself, returns a promise.
My problem is, that the controller never receives the resolved promise, after the modal closes. The modals result promise, where i resolve my promise, gets hit, and commentCount is the right value.
I'm new to the whole promise thing, so this might not be the correct way to do it, but shouldn't it work as it is now?
EDIT:
I'm not just returning the promise from instance.result, because i need to do something else inside the service, before returning the commentCount to the caller of the function. This is not implemented yet, though.
service:
function postModal($http, $rootScope, $uibModal, userService, utilService, enumService, $q) {
var service = {};
service.showModal = function (postId, category) {
var deferred = $q.defer();
var extraClass = (category == enumService.postType.ARTICLE) ? 'article-post' : '';
var instance = $uibModal.open({
templateUrl: 'app/views/post_modal.html',
controller: 'postController',
controllerAs: 'postController',
windowClass: 'center-modal post-modal',
backdropClass: 'post-backdrop ' + extraClass,
background: 'static',
resolve: {
postId: function () {
return postId;
},
category: function () {
return category;
},
modalInstance: function () {
return this;
}
}
});
instance.result.then(function (commentCount) {
deferred.resolve(commentCount);
});
return deferred.promise;
};
return service;
}
Code from controller:
service.showModal(postId, category)
.then(function (commentCount) {
var comments = commentCount;
});