Well, I'm having the following problem, i have a model windows that i can access form a controller, the problem is i need it to be accessible from more than one controller, so i thought to myself, "maybe i can create factory that i can inject into my controller and call the modal from there?" and so i tried the following :
.factory('FSTestService', function ($rootScope, $ionicModal) {
var completed = false;
var loggedIn = false;
// Create the ILS questionnaire modal that we will use later
$ionicModal.fromTemplateUrl('templates/FS-Form-container.html', {
scope: $rootScope
}).then(function (modal) {
$rootScope.FSModal = modal;
});
return {
FSFrom: function () {
$rootScope.FSModal.show();
}
}
})
and then on the controller i tried:
.controller('CursosCtrl', function ($scope, CursosService, FSTestService) {
FSTestService.FSForm;
})
But nothing happens, and if i go and call the "FSForm" as a function, that is to say change the aforementioned code as follows:
.controller('CursosCtrl', function ($scope, CursosService, FSTestService) {
FSTestService.FSForm();
})
I just get a bunch of error everywhere, so my question is, is this even possible ? what would be the standard way to proceed ?.
Based on this question and other needs I create a service that can be useful.
See this post: Ionic modal service
or see in operation: CodePen
I am currently looking into the same problem and found this solution. I know I'm pretty late on this, but better late than never!
It's then just a matter of calling $scope.modal1() or $scope.modal2() from your markup.