Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular-ui modal - pass data into modal

I am trying to pass some model data into a modal window when it is opened. When the user clicks on an element I want to have the modal window open and display more detailed information relating to what was clicked on.

I have created a plunker that works how I want it to except for passing the data into the modal window.

I am trying to pass the data in using ng-click:

<img ng-src="{{item.picture}}" width="100" ng-click="open(item)"/>

Can anyone help me with this? or point me in the right direction?

like image 269
mcneela86 Avatar asked Nov 04 '14 23:11

mcneela86


People also ask

How can I get dynamic data from bootstrap modal?

Load Dynamic Content from Database in Bootstrap ModalBy clicking the Open Modal ( . openBtn ) button, the dynamic content is loaded from another PHP file ( getContent. php ) based on the ID and shows on the modal popup ( #myModal ).

What does data toggle modal do?

data-toggle = “modal” Modal is dialog box/pop up displayed on the top of a page when an event occurs. For example, when a button is clicked, a pop-up appears.


2 Answers

How about this?

I added the item to the resolve

resolve: {
    items: function () {
        return $scope.items;
    },
    item: function(){
        return size;
    }
}

And in the controller I am doing: $scope.item = item; after injecting the item

like image 122
Mati Tucci Avatar answered Oct 05 '22 04:10

Mati Tucci


I've made a plunker for you at http://plnkr.co/FzU5SOv3pdZmAPAIOzdo.

You want to resolve your data much like you do items currently.

$scope.open = function (size) {

var modalInstance = $modal.open({
  templateUrl: 'myModalContent.html',
  controller: 'ModalInstanceCtrl',
  resolve: {
    items: function () {
      return $scope.items;
    },
    size: function() {
      console.log('size: ', size);
      return size;
    }
  }
});

and in your modal controller make sure to include the now resolved size object as follows:

angular.module('ui.bootstrap.demo').controller('ModalInstanceCtrl', function ($scope, $modalInstance, items, size) {

  $scope.items = items;
  $scope.selected = {
    item: $scope.items[0]
  };
  $scope.size = size;

  $scope.ok = function () {
    $modalInstance.close($scope.selected.item);
  };

  $scope.cancel = function () {
    $modalInstance.dismiss('cancel');
  };
});
like image 24
rtucker88 Avatar answered Oct 05 '22 03:10

rtucker88