0

I have to pass some data from a get to a Modal window, by eg. I use "item" for "response.data.item"...

$http.get(link).then(function (response) {

    var modalInstance = $uibModal.open({
        templateUrl: 'newsModal.html',
        controller: 'NewsModalInstanceCtrl',
        resolve: {
            item: function () {
                return response.data.item; // !! response undefined
            }
        }
    });

My problem is that the "response" is "undefined"... what is the right way to pass that parameter to the modal?

Edit: Is there another way that passing the $scope to the Modal controller...? I would like to have only the moldal information in the modal window, not all the response data from the link...

serge
  • 13,940
  • 35
  • 121
  • 205
  • Possible duplicate of [AngularJS passing data to bootstrap modal](http://stackoverflow.com/questions/33286851/angularjs-passing-data-to-bootstrap-modal) – bamtheboozle May 16 '17 at 15:13
  • I already seen that post before asking this question. I would't like to pass the scope – serge May 16 '17 at 15:17

2 Answers2

2

It should be like this

 var modalInstance = $uibModal.open({
    templateUrl: 'newsModal.html',
    controller: 'NewsModalInstanceCtrl',
    resolve: {
        item: function () {
          $http.get(link).then(function (response) {
                 return response.data.item;
          }
        }
});
Hadi J
  • 16,989
  • 4
  • 36
  • 62
  • as the get is not a syncronous function, the Item is always empty because is too late... – serge May 16 '17 at 15:37
0

I believe you have to pass it into the function

$http.get(link).then(function (response) {

var modalInstance = $uibModal.open({
    templateUrl: 'newsModal.html',
    controller: 'NewsModalInstanceCtrl',
    resolve: {
        item: function (response) {
            return response.data.item;
        }
    }
});

However, I have not tested this code.

Jens Stragier
  • 214
  • 1
  • 11
  • does not recognize the "response" parameter in the function: angular.js:12798 Error: [$injector:unpr] Unknown provider: responseProvider <- response – serge May 16 '17 at 15:46