1

This is a follow-up question to Angular-ui modal, sending data into modal controller from $http

I have the following code where I want to get data via a factory to the modal.

$scope.docSetup = function() {

  var modalInstance = $modal.open({
     templateUrl : '/templates/dialog/docSetup.html',
     controller  : 'docSetupDlgCtrl',
     resolve     :  {
        dlgData : function(){
           return TagService.list($scope.publication.id);
        }
     }
  });
  modalInstance.result.then(function (dlgData) {

     $log.debug(dlgData);

  }, function () {
     $log.debug('Modal dismissed at: ' + new Date());
  });
};

And here is the factory:

app.factory("TagService", function($http, $log){
   return {
      list: function(selectedDoc){

         $log.info("Tag service at work => list");

         var httpPromise = $http.post("tags/list", { publicationId: selectedDoc });

         httpPromise.then(function (response) {

            $log.log(response.data);
            return response.data;

         }, function (error) {
            $log.error(error);
         });
      }
   }
});

The above isn't resolving any data into dlgData. The factory is producing data and if I hardcode the data object into the 'resolve' function, it passes it.

1 Answer 1

2

return the entire httpPromise as well:

return httpPromise.then(function (response) {
    $log.log(response.data);
    return response.data;

 }, function (error) {
    $log.error(error);
 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.