Whenever I attempt to access a property of the object named "User," it shows up as undefined. However, upon logging the complete object to the console, the field appears with the necessary data.
Here is the console log output:
perfil.component.ts:42 undefined
perfil.component.ts:48
{recordNumber: '00001A', name: 'Victor Manuel Arenas', dni: '75499109E', birthDate: '2000-12-04', phoneNumber: '678678678', …}
address
:
"C\\Lorca 31"
birthDate
:
"2000-12-04"
dni
:
"75499109E"
email
:
"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8dfbe4eef9e2ffe0ece3f8e8e1a3ecffe8e3ecfecdf8e3e4fba3eee2e0">[email protected]</a>"
name
:
"Victor Manuel Arenas"
parking
:
null
password
:
"$2a$10$auBcwSsgKBWMTUUFToVb1OklqDP4O0LvW9F7vqWjnVZAGFzOVtfg6"
phoneNumber
:
"678678678"
profilepic
:
"profilepic_00001A.jpg"
recordNumber
:
"00001A"
role
:
"ALUMNO"
Method:
checking(){
if(this.sesion.user != null){
console.log(this.sesion.user.phonenumber);
if(this.sesion.user.phonenumber === undefined) {
alert("myProperty value is the special value `undefined`");
}
}
console.log(this.sesion.user);
}
User Interface:
import { Parking } from "./Parking";
export interface User {
recordNumber: string;
name: string;
dni: string;
birthdate: Date;
phonenumber: string|null;
email: string;
address: string;
profilepic: string|null;
role: string;
password: string;
parking: Parking;
}
I have attempted various methods and pages to access this field but face no backend issues as the data reaches the front-end successfully. The problem does not lie in the object itself since the field contains the necessary data.