Skip to content

Commit 9ab3818

Browse files
dotansimhadarkbasic
authored andcommitted
Step 7.16: Added verification component
1 parent afd7cd0 commit 9ab3818

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { AlertController, NavController, NavParams } from 'ionic-angular';
3+
import { PhoneService } from '../../services/phone';
4+
5+
@Component({
6+
selector: 'verification',
7+
templateUrl: 'verification.html'
8+
})
9+
export class VerificationPage implements OnInit {
10+
private code: string = '';
11+
private phone: string;
12+
13+
constructor(
14+
private alertCtrl: AlertController,
15+
private navCtrl: NavController,
16+
private navParams: NavParams,
17+
private phoneService: PhoneService
18+
) {}
19+
20+
ngOnInit() {
21+
this.phone = this.navParams.get('phone');
22+
}
23+
24+
onInputKeypress({keyCode}: KeyboardEvent): void {
25+
if (keyCode === 13) {
26+
this.verify();
27+
}
28+
}
29+
30+
verify(): void {
31+
this.phoneService.login(this.phone, this.code)
32+
.catch((e) => {
33+
this.handleError(e);
34+
});
35+
}
36+
37+
handleError(e: Error): void {
38+
console.error(e);
39+
40+
const alert = this.alertCtrl.create({
41+
title: 'Oops!',
42+
message: e.message,
43+
buttons: ['OK']
44+
});
45+
46+
alert.present();
47+
}
48+
}

0 commit comments

Comments
 (0)