Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass id value to ionic modal on click

I am using a click event to open a modal window like this ,

But on this click event i need to pass an id value so that i can dispaly the details wit respect to that id value .this is the controller part ,

           $ionicModal.fromTemplateUrl('modal.html', function($ionicModal) {
                $scope.modal = $ionicModal;
            }, {
                // Use our scope for the scope of the modal to keep it simple
                scope: $scope,
                // The animation we want to use for the modal entrance
                animation: 'slide-in-up'
            });  

is there any way to do this...???

Thanks.

like image 712
a4DEVP Avatar asked Jun 24 '15 07:06

a4DEVP


People also ask

How do you pass value to modal Ionic?

Passing data to an Ionic modal This is as simple as calling the componentProps on our modalController create function. number: number = 3; const modal = await this. modalController. create({ component: DetailPage, componentProps: { number: this.


2 Answers

If one needs to show up HTML content in model from scope. You will need to use

$scope.openModal = function(item) {
  $scope.modal=$ionicModal.fromTemplate('<ion-modal-view><b>'+item.id+'</b> 
  </ion-modal-view>',
  { animation: 'slide-in-up'});
  $scope.modal.open();
}
like image 67
Arjun G N Avatar answered Oct 29 '22 11:10

Arjun G N


You assign the current scope to your modal, so you can just assign the variable to the $scope object:

$ionicModal.fromTemplateUrl('modal.html', function($ionicModal) {
    $scope.modal = $ionicModal;
}, {
    // Use our scope for the scope of the modal to keep it simple
    scope: $scope,
    // The animation we want to use for the modal entrance
    animation: 'slide-in-up'
});

$scope.openModal = function(id) {
    $scope.selectedId = id;
    $scope.modal.show();
}

And in your view:

<ul>
    <li ng-repeat="item in items"
        ng-click="openModal(item.id)">
        {{ item.name }}
    </li>
</ul>

Then you have access to the id in your modal:

<div class="modal">
    <h1>{{ selectedId }}</h1>
</div>
like image 28
devqon Avatar answered Oct 29 '22 12:10

devqon