I am very new to ionic and not a pro with angular. I am trying to create a service for popups that I can call from a controller. I am using a service because multiple controllers may need to use the popups and I may need different kinds of popups. I'm not even sure this is the right approach please forgive me but I'm experimenting. I would like the service to pass back to the controller which button (Ok/Cancel) has been clicked so a case can be added or not.
Many thanks.
popupService
angular.module('services')
.service('popupService', function ($ionicPopup) {
return {
createCasePopup : function () {
$ionicPopup.show({
cssClass: 'custom-popup',
title: 'Create Case',
subTitle: 'Are you sure you want to create this case?',
buttons: [
{
text: 'Cancel',
onTap: function (e) {
return 'cancel button pressed';
}
},
{
text: 'Ok',
type: 'button-positive',
onTap: function (e) {
return 'ok button pressed';
}
},
]
}).then(
function (res) {
console.log(res);
},
function (err) {
console.log('Err:', err);
},
function (msg) {
console.log('message:', msg);
});
}
}
});
Controller
$scope.addCase = function () {
// this line to return which button has been clicked?
var createCase = popupService.createCasePopup();
if (createCase && $scope.case) {
caseService.add($scope.case);
}
};