Skip to content

Instantly share code, notes, and snippets.

@adash333
Created June 8, 2018 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adash333/64ba661e693fb4f90b85a11019ade371 to your computer and use it in GitHub Desktop.
Save adash333/64ba661e693fb4f90b85a11019ade371 to your computer and use it in GitHub Desktop.
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