import { AfterViewInit , Component } from '@angular/core' ; import { Router } from '@angular/router' ; import { AlertController } from '@ionic/angular' ; import { UserData } from '../../providers/user-data' ; @ Component ( { selector : 'page-account' , templateUrl : 'account.html' , styleUrls : [ './account.scss' ] , } ) export class AccountPage implements AfterViewInit { username : string ; constructor ( public alertCtrl , public router , public userData ) { } ngAfterViewInit ( ) { this . getUsername ( ) ; } updatePicture ( ) { console . log ( 'Clicked to update picture' ) ; } async changeUsername ( ) { const alert = await this . alertCtrl . create ( { header : 'Change Username' , buttons : [ 'Cancel' , { text : 'Ok' , handler : ( data ) => { this . userData . setUsername ( data . username ) ; this . getUsername ( ) ; } } ] , inputs : [ { type : 'text' , name : 'username' , value : this . username , placeholder : 'username' } ] } ) ; await alert . present ( ) ; } getUsername ( ) { this . userData . getUsername ( ) . then ( ( username ) => { this . username = username ; } ) ; } changePassword ( ) { console . log ( 'Clicked to change password' ) ; } logout ( ) { this . userData . logout ( ) ; this . router . navigateByUrl ( '/login' ) ; } support ( ) { this . router . navigateByUrl ( '/support' ) ; } }