Trouble creating Dynamic ionicmodal


#1

Hi there,

I’ve been working with $ionicModal and i’ve found some problems trying to insert dynamic content on them.

I have a controller “controller1” which has the $ionicModal module that opens a modal.

The modal uses a controller called “controller2”, and in this second controller I have a Scope var which is printed on the modal.

The thing is that i want the modal to change the scope value depending on the button the user clicks on my view (a function fired on controller1). For example “openModal(1)” and so…

I’ve tried to use rootscope, and an external service to share vars between the controllers with no luck.

I’ve also tried to inject the $ionicModal service on “controller2” and move the function “openModal” to the controller 2, and use "ng-controller=“controller2” on the buttons, but it has entered on a bucle that has crashed my crome several times before finding what the heck was happening.

Is the modal intended to use only with static content?
If someone could give me a hint about updating content inside of a modal with and external controller. I would be very appreciated.

Thanks


#2

At the end i’ve found a solution, but i still want to leave my post open in case someone provides a better solution.

What i’ve done is to make a function on my buttons “openModal(1)”, which in addition to open the modal, sets on rootscope, the value of the parameter.

In the controller2 i’ve done a $watch on $rootscope to apply that value on the view.

$rootScope.$watch('avisosLinea', function(newValue, oldValue) {

$scope.var = newValue;

});

#3

Using the rootScope and watchers are not the best way i think.

Maybe you can use angulars event system to inform child/parent controllers.
You may have a look for $emit, $broadcast.

Greets, bengtler.


#4

Looks exactly what i’m looking for.
Thanks!