Here's how I manage my singleton modal

I needed to keep my DOM lean since I’m loading a ton of content into a modal (a map). So to conserve, I did this to keep a single modal instance for a specific view/controller.

$ionicModal.fromTemplateUrl(‘templates/groups/map.html’, {
scope: $scope
}).then(function(modal) {
$scope.modal = modal;
});
$scope.$on(’$destroy’, function() {
if ($scope.modal) $scope.modal.remove();
});
$scope.showMap = function(coords) {
$scope.modal.show().then(function() {
// do something with map…
});
};

1 Like