Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass a controller to $ionicModal

I am wondering if you can pass a controller to the $ionicModal service. Something like.

$ionicModal.fromTemplateUrl('templates/login.html', {   scope: $scope,   controller: 'MyModalCotroller' }) 

A little context: I would like to have a modal that is distributed across the app and I dont want to repeat all the methods (hide, show, buttons inside the modal) in every controller and I would like to remove the methods from the 'Main Controller' to keep things clean. This would encapsulate the functionality of the modal.

Is there a way to do this.? Thanks

like image 828
Juan Solano Avatar asked Dec 11 '14 23:12

Juan Solano


People also ask

How do you pass data to modalController in 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.

What is modal controller?

Improve this doc. A Modal is a content pane that goes over the user's current page. Usually it is used for making a choice or editing an item. A modal uses the NavController to present itself in the root nav stack.


1 Answers

Just add the controller you want to use in the body of the html of the modal. I created a fiddle to show you an example based off the one provided in the ionic docs: http://jsfiddle.net/g6pdkfL8/

But basically:

<-- template for the modal window --> <ion-modal-view> <ion-content ng-controller="ModalController">  ... </ion-content> <ion-modal-view> 
like image 97
RipTheJacker Avatar answered Sep 20 '22 12:09

RipTheJacker