I know ideally using an Actionsheet will solve my problem here, but I want to know if it is possible to connect a button in an ionicPopup to the controller that is invoking it via ng-click directive. I originally thought the ng-click directive will introduce the $scope of the controller, but it doesn't seem to be the case. So does that mean we cannot connect buttons to the controller in an ionicPopup?
$ionicPopup returns promises.
Let's say your view has a button which invokes (ng-click) a method in your controller:
<button class="button button-primary" ng-click="showConfirm()">Confirm</button>
In your controller you would invoke your popup doing something like this:
$scope.showConfirm = function() {
var confirmPopup = $ionicPopup.confirm({
title: 'Consume Ice Cream',
template: 'Are you sure you want to eat this ice cream?'
});
confirmPopup.then(function(res) {
if(res) {
console.log('You are sure');
} else {
console.log('You are not sure');
}
});
};
When a user has tapped on one of the 2 buttons in the confirm dialog you can read the result and do some other things.
confirmPopup.then(function(res) {
if(res) {
console.log('You are sure');
} else {
console.log('You are not sure');
}
});
I can not understand 100% your question, but I guess you need a button within a "$ ionicPopup" call a function of the controller? if so, I leave this.
$ionicPopup.show({
title: 'Información View',
subTitle: '',
content: 'Content'
scope: $scope,
buttons: [{
text: 'Exit',
onTap: function(e) {
//Call function by pressing button exit
}
}, {
text: 'Ok',
type: 'button-positive',
onTap: function(e) {
//Call function by pressing button Ok
}
}, ]
})
}