How to open an ionic modal at a certain state


#1

Is there a way to open an ionic Modal at a certain state?

I found in the ui-router docs an example using the bootstrap $modal service but I have no idea how to apply the $ionicModal service instead.


#2

Try this,

$ionicModal.fromTemplateUrl('modal.html', {	
    scope: $scope,
    animation: 'slide-in-up'
})
.then(function(modal) {
    $scope.modal = modal;
    $scope.modal.show();
});

This will immediately open a modal with template modal.html. Put this where the state’s controller is.


#3

Just a minor improvement, move the $scope.modal.show() into the .then() callback.


#4

I found this example in codepen: