Well, I have a class:
export class Usuario{
private id : string;
private bluetoothMAC: string;
private cpf: string;
private nome: string;
private oficinaVisitadas: Oficina[];
private cacheMAC: Mac[];
private saidaMAC: Mac[];
constructor(){
}
//gets and sets
I have this method that returns the user
getUserKeyMAC(MAC: string):Usuario{
let key: string = ""
let oMAC: string = ""
let rt: any;
let us:any;
oMAC = MAC
this.items = this.angularFire.list('/Usuarios', { preserveSnapshot: true });
us = new Usuario
this.items.subscribe(snapshots => {
snapshots.forEach(snapshot => {
let arrayTemp:any
let aMAC: string = ""
aMAC = snapshot.val().bluetoothMAC
if (aMAC === oMAC) {
us.$id=snapshot.key
us.$nome = snapshot.val().nome;
us.$cpf = snapshot.val().cpf;
us.$bluetoothMAC = snapshot.val().bluetoothMAC;
arrayTemp= new Array;
arrayTemp = snapshot.val().oficinaVisitadas
us.$oficinaVisitadas=arrayTemp
}
});
})
return us
}
And here where I get the return, I try to print any attribute of the user, but it comes as undefined:
marcaEntrada(obs:Observable<Mac[]>){
obs.subscribe(macs=>{
macs.forEach((mac)=>{
let us:any;
us = new Usuario;
us=this.hfb.getUserKeyMAC(String(mac.mac));
console.log(us.$id);
})
})
}
butifyoutrytoprintthewholeobjectitappearsnormally: