TypeError: Cannot read property 'email' of undefined


I created a project with firebase. A user was created successfully by email and password. Now, i am trying to login with this email and password but It is not logging and gives an error in the console.

TypeError: Cannot read property 'email' of undefined
    at LoginPage.<anonymous> (login.ts:28)
    at step (main.js:96)
    at Object.next (main.js:77)
    at main.js:71
    at new t (polyfills.js:3)
    at webpackJsonp.101.__awaiter (main.js:67)
    at LoginPage.webpackJsonp.101.LoginPage.login (login.ts:26)
    at Object.eval [as handleEvent] (LoginPage.html:12)
    at handleEvent (core.es5.js:11914)
    at callWithDebugContext (core.es5.js:13206)


import { Component } from '@angular/core';
import { AlertController, App, LoadingController, NavController, IonicPage } from 'ionic-angular';
import { SignupPage } from '../signup/signup';
import { AngularFireAuth } from "angularfire2/auth"
import { User } from "../../models/user";
import { DerslerPage } from '../dersler/dersler';

  selector: 'login',
  templateUrl: 'login.html',
export class LoginPage {

  public loginForm: any;

  user = {} as User;

  constructor(private afAuth: AngularFireAuth,
    private navCtrl: NavController, public loadingCtrl: LoadingController, public alertCtrl: AlertController, public app: App) {

  async login(user: User) {
    try {
      const result = this.afAuth.auth.signInWithEmailAndPassword(user.email, user.password);
      if (result) {
    catch (e) {


<ion-content padding class="transparent-header">
  <div padding>
      <ion-input type="text" [(ngModel)]="user.email" placeholder="Email"></ion-input>
      <ion-input type="password" [(ngModel)]="user.password" placeholder="Password" ></ion-input>
    <button ion-button block outline (click)="login()" color="light" class="login-button">Login</button>
  <div class="strike">
  <button ion-button block clear (click)="login()" color="light" class="login-button"><ion-icon name="logo-facebook"></ion-icon> Login with Facebook</button>
  <button ion-button block clear (click)="login()" color="light" class="login-button"><ion-icon name="logo-googleplus"></ion-icon> Login with Google</button>
  <ion-toolbar class="footer">
    <div (click)="goToSignup()">
      <span>Don't have an account? <strong>Sign up here</strong>.</span>


import { LoginPage } from './login';
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';

    declarations: [
    imports: [
    exports: [

export class LoginPageModule { };

What may be the problem?


async/await is a bad fit for AngularFire, which is Observable-based. If you change your code to use Observables and FirebaseObjectObservables, etc., you’ll probably find the problem…


Thank you for your response

What does it mean changing the code to use observables and FirebaseObjectObservables?

You’re login.ts file contains a function login(user :User). From that object, you request the email value.
In your HTML file, you call the function login(), but without the user object. The login function is executed, but you are now requesting an email value, of an undefined object, because you didn’t provide one. Change
login() to login(user).

1 Like

Oh yeah, you are right. I couldn’t see it.

It worked for me. Thanks

I’m getting error as

my login.ts contains

My home.ts is as

Please help me out