Hello my Ionic project has the following error (Error: Uncaught (in promise): TypeError: Can not read property '0' of undefined) Attached is an image of the problem. I would like some hint Followtheprojectlink.
link
login.ts
import { Component } from '@angular/core';
//import { NgForm } from '@angular/forms';
import { NavController, ToastController } from 'ionic-angular';
import { UserData } from '../../providers/user-data/user-data';
import { AuthService } from
"../../providers/authservice/authservice";
import { UserOptions } from '../../components/user-options/user-
options';
import { Storage } from "@ionic/storage";
import { UserPage } from '../user/user';
@Component({
selector: 'page-user',
templateUrl: 'login.html'
})
export class LoginPage {
login: UserOptions = { username: '', password: '' };
userData= {"username":"", "password":""};
responseData: any;
public userInfo: any;
public dataSet: any;
submitted = false;
constructor(
public navCtrl: NavController,
public loginData: UserData,
public authService: AuthService,
public storage: Storage,
public toastCtrl: ToastController
) { }
//onLogin(form: NgForm) {
onLogin() {
this.submitted = true;
this.dataSet = [];
//var userdatalocal;
if(this.userData.username && this.userData.password){
//API connection
this.authService.postData(this.userData, "login")
.then((result) => {
this.responseData = result;
if(this.responseData){
this.dataSet = this.responseData;
//localStorage.setItem('userData',JSON.stringify(this.responseData));
//this.storage.set('userData',JSON.stringify(this.responseData));
this.userInfo = this.dataSet.userId[0].userData;
// console.log(this.dataSet.userId[0].userData.email);
this.loginData.login(this.userData.username); //para setar flag
loggedInMenu
this.navCtrl.push(UserPage,this.dataSet);
} else {
// If login or password is invalid then return to LoginPage
console.log("Erro18r: login/password invalid or bad connection");
this.navCtrl.setPages([
{page: LoginPage}
]) ;
let toast = this.toastCtrl.create({
message: this.responseData.error.text ,//'Login or password
incorrect.',
duration: 5000
});
toast.present();
}
}, (err) => {
//Connection failure message
console.log(err);
this.navCtrl.setPages([
{page: LoginPage}
]) ;
})
}
}
}