import { Component } from '@angular/core' ; import { NgForm } from '@angular/forms' ; import { AlertController , NavController , ToastController } from 'ionic-angular' ; @ Component ( { selector : 'page-user' , templateUrl : 'support.html' } ) export class SupportPage { submitted : boolean = false ; supportMessage : string ; constructor ( public navCtrl , public alertCtrl , public toastCtrl ) { } ionViewDidEnter ( ) { let toast = this . toastCtrl . create ( { message : 'This does not actually send a support request.' , duration : 3000 } ) ; toast . present ( ) ; } submit ( form ) { this . submitted = true ; if ( form . valid ) { this . supportMessage = '' ; this . submitted = false ; let toast = this . toastCtrl . create ( { message : 'Your support request has been sent.' , duration : 3000 } ) ; toast . present ( ) ; } } ionViewCanLeave ( ) { if ( ! this . supportMessage || this . supportMessage . trim ( ) . length === 0 ) { return true ; } return new Promise ( ( resolve , reject ) => { let alert = this . alertCtrl . create ( { title : 'Leave this page?' , message : 'Are you sure you want to leave this page? Your support message will not be submitted.' } ) ; alert . addButton ( { text : 'Stay' , handler : reject } ) ; alert . addButton ( { text : 'Leave' , role : 'cancel' , handler : resolve } ) ; alert . present ( ) ; } ) ; } }