In my setup, I have a Component and a Service:
Component:
export class WebUserProfileViewComponent {
persons: Person [];
personId: number;
constructor( params: RouteParams, private personService: PersonService) {
this.personId = params.get('id');
this.persons = this. personService.getPersons();
console.log(this.personId);
}
}
Service:
@Injectable()
export class PersonService {
getPersons(){
var persons: Person[] = [
{id: 1, firstName:'Hans', lastName:'Mustermann', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6c01191f18091e010d02022c18...},
{id: 2, firstName:'Muster', lastName:'Mustermann', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dbb6ae...},
{id:3, firstName:'Thomas', lastName:'Mustermann', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2b465e585f4...}
];
return persons;
}
}
I am currently trying to retrieve the Person item based on the ID ('personID'), which I obtain from Routeparams
. I am considering using a foreach loop, but I have not been able to find the right solution yet.