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?
Asked
Active
Viewed 1,523 times
1
-
I clearly don't understand your question – aorfevre May 15 '15 at 12:16
-
Some code would be helpful... – LarsBauer May 17 '15 at 11:14
-
Did you manage to find a solutions? – LeftyX May 21 '15 at 08:16
2 Answers
0
$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');
}
});

LeftyX
- 35,328
- 21
- 132
- 193
0
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
}
}, ]
})
}

NHTorres
- 1,528
- 2
- 21
- 39
-
I want to change the $state on tap of the button but it is not working. Any advice? – Samarth Agarwal Feb 06 '16 at 18:18
-
1Hi, Thanks. Finally I got it working. I had wrong `views` property set in the state. – Samarth Agarwal Feb 09 '16 at 13:55