Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step 7.16: Added verification component
- Loading branch information
1 parent
afd7cd0
commit 9ab3818
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { AlertController, NavController, NavParams } from 'ionic-angular'; | ||
import { PhoneService } from '../../services/phone'; | ||
|
||
@Component({ | ||
selector: 'verification', | ||
templateUrl: 'verification.html' | ||
}) | ||
export class VerificationPage implements OnInit { | ||
private code: string = ''; | ||
private phone: string; | ||
|
||
constructor( | ||
private alertCtrl: AlertController, | ||
private navCtrl: NavController, | ||
private navParams: NavParams, | ||
private phoneService: PhoneService | ||
) {} | ||
|
||
ngOnInit() { | ||
this.phone = this.navParams.get('phone'); | ||
} | ||
|
||
onInputKeypress({keyCode}: KeyboardEvent): void { | ||
if (keyCode === 13) { | ||
this.verify(); | ||
} | ||
} | ||
|
||
verify(): void { | ||
this.phoneService.login(this.phone, this.code) | ||
.catch((e) => { | ||
this.handleError(e); | ||
}); | ||
} | ||
|
||
handleError(e: Error): void { | ||
console.error(e); | ||
|
||
const alert = this.alertCtrl.create({ | ||
title: 'Oops!', | ||
message: e.message, | ||
buttons: ['OK'] | ||
}); | ||
|
||
alert.present(); | ||
} | ||
} |