Skip to content

Instantly share code, notes, and snippets.

@nicon-dev
Created July 20, 2015 21:52
Show Gist options
  • Save nicon-dev/9be16613a08c2be7527a to your computer and use it in GitHub Desktop.
Save nicon-dev/9be16613a08c2be7527a to your computer and use it in GitHub Desktop.
IONIC: Popups
// Alert popup
// Just Text and one OK button
var alertPopup = $ionicPopup.alert({
title: 'Don\'t eat that!',
template: 'It might taste good'
});
alertPopup.then(function(res) {
console.log('Thank you for not eating my delicious ice cream cone');
});
//a confirm dialog
// with text, Ok and Cancel buttons
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');
}
});
// An elaborate, custom popup
// Popup with Input, Cancel, Save
var myPopup = $ionicPopup.show({
template: '<input type="password" ng-model="data.wifi">',
title: 'Enter Wi-Fi Password',
subTitle: 'Please use normal things',
scope: $scope,
buttons: [
{ text: 'Cancel' },
{
text: '<b>Save</b>',
type: 'button-positive',
onTap: function(e) {
if (!$scope.data.wifi) {
//don't allow the user to close unless he enters wifi password
e.preventDefault();
} else {
return $scope.data.wifi;
}
}
}
]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment