Created
June 8, 2018 12:39
-
-
Save adash333/64ba661e693fb4f90b85a11019ade371 to your computer and use it in GitHub Desktop.
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
import { Component } from '@angular/core'; | |
import { IonicPage, NavController, NavParams } from 'ionic-angular'; | |
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; | |
import { AuthProvider } from '../../providers/auth/auth'; | |
import { HomePage } from '../home/home'; | |
@IonicPage() | |
@Component({ | |
selector: 'page-login', | |
templateUrl: 'login.html', | |
}) | |
export class LoginPage { | |
/** | |
* Create reference for FormGroup object | |
*/ | |
public form: FormGroup; | |
constructor( | |
public navCtrl: NavController, | |
public navParams: NavParams, | |
private _FB: FormBuilder, | |
private _AUTH: AuthProvider | |
) { | |
// Define FormGroup object using Angular's FormBuilder | |
this.form = this._FB.group({ | |
'email': ['', Validators.required], | |
'password': ['', Validators.required] | |
}); | |
} | |
/** | |
* Log in using the loginWithEmailAndPassword method | |
* from the AuthProvider service (supplying the email | |
* and password FormControls from the template via the | |
* FormBuilder object) | |
* @method login | |
* @return {none} | |
*/ | |
logIn(): void { | |
let email: any = this.form.controls['email'].value, | |
password: any = this.form.controls['password'].value; | |
this._AUTH.loginWithEmailAndPassword(email, password).then((auth: any) => { | |
this.navCtrl.setRoot(HomePage); | |
}).catch((error: any) => { | |
console.log(error.message); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment