I am trying to figure out how to pass a complete object to my modal so that I can view all of its attributes there. Currently, the items I have look like this:
$scope.items = [{ Title: title, Id: id }]
On my html page, I am using 'ng-repeat' as follows:
<tr ng-repeat="item in items | filter:search">
<td> {{item.Title}} </td>
<td> {{item.Id}} </td>
<td> <button ng-controller="ModalDemoCtrl" type="button" ng-click="viewItem(item)" class="btn btn-primary">View Item</button> </td>
And here is my modal html code:
<div class="modal-header">
<h3>{{Title }}</h3>
</div>
<div class="modal-body">
<p>{{ Id }}</p>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">OK</button>
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
Currently, I am only able to display two values from the item.
I am struggling with how my modalController should be set up in order to pass the entire item (which currently only has a title and an ID) to the modal view.
The example on the angular bootstrap github page was followed while creating my controller:
angular.module('ui.bootstrap.demo').controller('ModalDemoCtrl', function ($scope, $modal, $log) {
$scope.viewItem = function () {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
resolve: {
items: function () {
return $scope.items;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
angular.module('ui.bootstrap.demo').controller('ModalInstanceCtrl', function ($scope, $modalInstance, items) {
$scope.items = items;
$scope.selected = {
item: $scope.items[0]
};
$scope.ok = function () {
$modalInstance.close($scope.selected.item);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
});
I understand that the current setup may not work as expected. I will update with my actual controller later tonight. Any suggestions on how I can achieve this would be greatly appreciated.