hi I'm trying to output multiple bootstrap 3 panels with a heading and list items with angular2 getting data from a web api
functions in my service.ts:
with the following function I get a json containing the panel headings which are components i will use
getComponents(type: string): Observable<string[]> {
return this.http.get('http://localhost:14373/api/devices/components/' + type)
.map((response: Response) => response.json());
}
And with this function I get a json containing all values which will be the list items
getComponentValues(type: string, component: string): Observable<string[]> {
return this.http.get('http://localhost:14373/api/devices/components/' + type + '/' + component)
.map((response: Response) => response.json());
}
in my component.ts I save the values of components (headings) in a string array with this function
ngOnInit() {
this.subscription = this.route.params
.subscribe(
(params: any) => {
this.currentType = params['type'];
this.deviceService.getComponents(this.currentType).subscribe(
(data: string[]) => {
this.components = data;
}
);
}
);
}
then I tried to write a function which will return the componentValues (list-items) as array and output them with a nested *ngFor loop.
getComponentValues(type: string, component: string) {
this.deviceService.getComponentValues(type, component)
.subscribe(
(data: string[]) => {
return data;
}
)
}
template:
<div class="panel panel-default" *ngFor="let component of components">
<!-- Default panel contents -->
<div class="panel-heading">{{component}}</div>
<!-- List group -->
<ul class="list-group">
<li class="list-group-item" *ngFor="let val of getComponentValues(currentType, component)">
{{val}}
</li>
</ul>
</div>
but this doesn't seem to work and since I've never even touched angular2 or angular before I don't know if I'm on the right track or which approach would actually be best practice.. also I obviously don't understand observables yet