我有一个组件和一个服务:
组成部分:
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);
}
}
服务范围:
@Injectable()
export class PersonService {
getPersons(){
var persons: Person[] = [
{id: 1, firstName:'Hans', lastName:'Mustermann', email: 'mustermann@test.com', company:'Test', country:'DE'},
{id: 2, firstName:'Muster', lastName:'Mustermann', email: 'mustermann@test.com', company:'test', country:'DE'},
{id:3, firstName:'Thomas', lastName:'Mustermann', email: 'mustermannt@tesrt.com', company:'test', country:'DE'}
];
return persons;
}
}
我希望获取 ID 为“ Person”的项(“ PersonID”)。我从 Routeparams
得到的人员编号。我需要 foreach 循环吗?但我还没找到解决办法。