I'm developing an app where I'm pulling data from a mongo database. I'm using string interpolation to pull in the data and print it to the view. It's working as expected for basic object data. So for instance, I'm able to take this from the db:
"name": {
"prefix": "",
"suffix": "",
"first": "",
"middle": "",
"last": ""
}
... and print it to the component view with string interpolation - like this:
{{record.name.first}} {{record.name.last}}
The component is subscribing to an observable I've set up in a service. In the component it looks like this:
ngOnInit() {
this.streamVisitingService.getByCat()
.subscribe(resRecordsData => this.records = resRecordsData,
responseRecordsError => this.errorMsg = responseRecordsError);
}
Abd here's the relevant code from my service:
constructor(private _http: Http) {}
getByCat() {
return this._http.get(this._url)
.map((response:Response) => response.json())
.catch(this._errorsHandler);
}
_errorsHandler(error: Response) {
console.error(error);
return Observable.throw(error || "Server Error");
}
My problem/challenge comes in trying to print to the screen data that's within an array of objects. How do I target a specific field/value that is within an object within an array? It may be obvious, but for some reason the answer is escaping me.