exit application after showing ionic popup - ionic-framework

I have this code in my application:
$ionicPopup.alert({
title: $scope.header1,
template: 'The was a problem connecting to the server. Please check your internet connection and try again.'
});
ionic.Platform.exitApp()
what I have noticed is that in Android, the application exits quickly without showing the pop up message. What I wanted to do is execute
ionic.Platform.exitApp()
after the user press the 'Ok' button in the pop-up. ls there something like an "onleave" event in ionic Popup?

The best approach may be to define your own 'OK' button as opposed to leveraging the default dismiss one - that way you can invoke ionic.Platform.exitApp() upon the user clicking/tapping your button.
Example:
import { AlertController } from 'ionic-angular';
constructor(private alertCtrl: AlertController) {
}
presentAlert() {
let alert = this.alertCtrl.create({
title: YourCustomHeader,
//subTitle: 'optional text',
message: 'The was a problem connecting to the server. Please check your internet connection and try again.',
buttons: [
{
text: 'OK',
handler: () => {
ionic.Platform.exitApp();
}
}
]
});
alert.present();
}
Reference: https://ionicframework.com/docs/api/components/alert/AlertController/#usage

Related

Ionic 2 Prompt Alert focus on text input

I am creating an ionic 2 application for android and ios. I have an alert controller that prompts the user for a text input, however when the alert pops up I would like the keyboard to focus on the input, and for the placeholder text to be highlighted. Currently you must tap on the text input for the keyboard to pop up. Is this possible to implement?
here is my alert controller code:
let prompt = this.alertCtrl.create({
title: this.name,
message: this.nameMessage,
inputs: [
{
name: 'name',
placeholder: this.name
},
],
buttons: [
{
text: this.save,
handler: data => {
resolve(data.name);
}
}
],
enableBackdropDismiss: false
});
prompt.present();
This is my solution.
First
inputs: [
{
id: "autofocu",
......
}
],
And then
alert.present()
.then(() => {
document.getElementById('autofocu').focus();
})
.catch()

Ionic 2 toast can't be dismissed manually

I am working on an ionic2 project and trying to show connection status message in the app. Here is my code:
import { ToastController, Toast } from 'ionic-angular';
connectedToast: Toast; disconnectedToast: Toast;
this.connectedToast = this.toast.create({
message: `You are now ${networkstatus.connectType} via ${networkstatus.networkType}`,
position: 'bottom',
cssClass: 'toast-connected',
duration: 3000
});
this.disconnectedToast = this.toast.create({
message: `This function is not available because you are ${networkstatus.connectType}`,
position: 'bottom',
cssClass: 'toast-disconnected'
});
if(networkstatus.isOnline) {
if(this.disconnectedToast != null)
this.disconnectedToast.dismiss();
this.connectedToast.present();
}
if(networkstatus.isOffline) this.disconnectedToast.present();
What I wanted to achieve is: if offline, toast msg will stay there until it is online. But for online message, it will only display for 3 seconds. Everything is working fine except when it is online and after online message is displayed, the offline toast msg stays there and didn't disappear even though I called dismiss(). Did I miss anything here?
my environment is: "ionic-angular": "3.3.0", "ionic": "3.6.0",
"typescript": "2.3.3"
Any help will be appreciated!

How to change Alert Direction into RTL in ionic 2?

Is there any way to change alert direction in ionic 2 ?
const alert = this.alertCtrl.create({
title: 'خطأ',
subTitle: 'GPS والوصول إلى الشبكة غير ممكن.',
enableBackdropDismiss: false,
buttons: [{
text: 'نعم',
handler: () => {
setTimeout(() => this.locate(), 1500);
}
}],
});
I tried and tested some css but fails.
I try but have a difficult way for change this.
Try use ionic AlertController
And set enableBackdropDismiss:false for work like alertCtrl

ionic InAppBrowser not firing event

Please help someone, below code opening page but not firing event
this._browser = this.inAppBrowser.create('http://www.google.com');
this._browser.on('loadstart').subscribe((event) => {
let alert1 = this._alertCtrl.create({
subTitle: 'load start',
buttons: ['ok!']
});
alert1.present();
});

How to put a checkbox input inside an alert prompt in Ionic2?

Using Ionic2 and Angular2, I want to show an alert box, inside which a text along with checkbox - to ask for user if he/she agree to the statement.
//Prompt an alert, to ask user to verify there email address.
let alert = Alert.create({
subTitle: 'Email not verified!',
message: 'Please check your email for verification link.',
inputs: [
{
name: 'getLink',
label: 'Get verification link again ?',
type: "checkbox",
value: "true",
checked: false
}
],
buttons: [
{
text: 'Ok',
handler: data => {
console.log(data);
if(data.length > 0) {
//console.log('Get me link');
//we are calling this method to sent a link to user over mail - to verify their email address.
user.sendEmailVerification();
this.nav.rootNav.setRoot(HomePage);
return true;
} else {
//console.log('Link not required!');
this.nav.rootNav.setRoot(HomePage);
return true;
}
}
}
]
});
this.nav.present(alert);