Following interpolation
{{ (__responseData | async)?.calculation | json }}
outputs following structure
[
{
"gross": 26.625834,
"net": 20.425833,
"tax": 6.2000003
}
]
How can I get gross?
{{ (__responseData | async)?.calculation[0].gross }}
does not work, and the all the following trys don't work too:
{{ (__responseData.calculation[0] | async)?.gross }}
{{ (__responseData.calculation.[0].gross | async) }}
What's the mistake?
EDIT: As workaround I use flatmap (this.__responseData.flatMap((data: any) => data.calculation);
) but I would like to have an elegant solution,..
That's the answer from Alexander (Angular2-Github-Platform)
You could use *ngFor="let calculation of calculations | async"
@Component({
selector: 'my-app',
providers: [HTTP_PROVIDERS],
template: `
<div *ngFor="let calculation of calculations | async">
Gross: {{ calculation.gross }}<br>
Net: {{ calculation.net }}
</div>
`,
directives: [NgFor]
})
export class App {
calculations: Observable<{gross:number; net:number}[]>;
constructor(private _http: Http) {
this.calculations = this._http.get("./data.json")
.map(res => res.json().calculation)
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments