I'm having problems displaying data from my local express.js REST API, which is structured like this:
people: [{ surname: 'testsurname', name: 'testname', email:
'[email protected]', status: 1, activity: 'Office' }
I have a people service where I get the data, it looks like this:
export interface People {
surname: String;
name: String;
email: String;
status: Boolean;
activity: String;
}
@Injectable()
export class PeopleService {
private _peopleURL = "http://localhost:8080/api/people";
constructor(private http: HttpClient) {
console.log('init PS')
}
getPeople(): Observable<People[]> {
return this.http
.get(this._peopleURL)
.map((response: Response) => {
return <People[]>response.json();
})
}
}
This is my PeopleComponent.ts code
export class PeopleComponent implements OnInit {
_peopleArray: People[];
constructor(private ps: PeopleService)
{ }
getPeople(): void {
this.ps.getPeople()
.subscribe(
resultArray => this._peopleArray = resultArray,
error => console.log("Error :: " + error)
)
}
ngOnInit(): void {
this.getPeople();
}
Now I'm trying to display the data (i.e. the name) in my 'People' component.html like so:
<div> {{people.name}} </div>
When I start my app I get an error saying
'TypeError: Cannot read property 'name' of undefined at Object.eval [as updateRenderer]
Can anyone explain to me what I missed and what I need to be doing in order to display the data?