I have an Array that collects a list. If I do a console.log (this);
I can see the array with the elements in the console.
But if I do the console.log(this.People);
it tells me it's undefined.
import { Component, OnInit,Input } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Person } from '../class/personClass';
import { ConexionPersonService } from '../conexion-person.service';
@Component({
selector: 'app-detail-user',
templateUrl: './detail-user.component.html',
styleUrls: ['./detail-user.component.css']
})
export class DetailUserComponent implements OnInit {
detailPerson: Person;
People:Person[];
@Input() id;
constructor(
private route: ActivatedRoute,
private conexion: ConexionPersonService) { }
ngOnInit() {
this.id = +this.route.snapshot.paramMap.get('id');
this.getPeople();
this.getPerson();
}
getPeople(): void {
//Aquí obtengo el array de People
this.conexion.getPeople()
.subscribe(People => this.People = People);
}
getPerson(): void {
console.log ( "this en getPerson" , this); //Aquí se ven los datos
console.log ( "persona en getPerson" , this.People); //Ya no
console.log ( "id en getPerson" , this.id);
this.detailPerson = this.conexion.getPerson(this.People,this.id);
}
}