1
Hello my Ionic project is with the following error (Error: Uncaught (in Promise): Typeerror: Cannot read Property '0' of Undefined) follows an attached image of the problem. I would like some hint. Follow the project link.
https://drive.google.com/open?id=1Ivez_R0Pv9RKR0D2EAoZD--1VqTBC8bf
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}
]) ;
})
}
}
}
Post the problem code here, isolate the part that happens this error and post here on the site. Probably no one will download your project to look for bugs.
– Jéf Bueno