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...

2
  • Possible duplicate of AngularJS passing data to bootstrap modal Commented May 16, 2017 at 15:13
  • I already seen that post before asking this question. I would't like to pass the scope Commented May 16, 2017 at 15:17

2 Answers 2

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;
          }
        }
});
Sign up to request clarification or add additional context in comments.

1 Comment

as the get is not a syncronous function, the Item is always empty because is too late...
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.

1 Comment

does not recognize the "response" parameter in the function: angular.js:12798 Error: [$injector:unpr] Unknown provider: responseProvider <- response

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.