File tree Expand file tree Collapse file tree 1 file changed +66
-0
lines changed
Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Component } from '@angular/core' ;
2+ import { Alert , AlertController , NavController } from 'ionic-angular' ;
3+ import { PhoneService } from '../../services/phone' ;
4+
5+ @Component ( {
6+ selector : 'login' ,
7+ templateUrl : 'login.html'
8+ } )
9+ export class LoginPage {
10+ private phone = '' ;
11+
12+ constructor (
13+ private alertCtrl : AlertController ,
14+ private phoneService : PhoneService ,
15+ private navCtrl : NavController
16+ ) { }
17+
18+ onInputKeypress ( { keyCode} : KeyboardEvent ) : void {
19+ if ( keyCode === 13 ) {
20+ this . login ( ) ;
21+ }
22+ }
23+
24+ login ( phone : string = this . phone ) : void {
25+ const alert = this . alertCtrl . create ( {
26+ title : 'Confirm' ,
27+ message : `Would you like to proceed with the phone number ${ phone } ?` ,
28+ buttons : [
29+ {
30+ text : 'Cancel' ,
31+ role : 'cancel'
32+ } ,
33+ {
34+ text : 'Yes' ,
35+ handler : ( ) => {
36+ this . handleLogin ( alert ) ;
37+ return false ;
38+ }
39+ }
40+ ]
41+ } ) ;
42+
43+ alert . present ( ) ;
44+ }
45+
46+ handleLogin ( alert : Alert ) : void {
47+ alert . dismiss ( ) . then ( ( ) => {
48+ return this . phoneService . verify ( this . phone ) ;
49+ } )
50+ . catch ( ( e ) => {
51+ this . handleError ( e ) ;
52+ } ) ;
53+ }
54+
55+ handleError ( e : Error ) : void {
56+ console . error ( e ) ;
57+
58+ const alert = this . alertCtrl . create ( {
59+ title : 'Oops!' ,
60+ message : e . message ,
61+ buttons : [ 'OK' ]
62+ } ) ;
63+
64+ alert . present ( ) ;
65+ }
66+ }
You can’t perform that action at this time.
0 commit comments