1

We have a model which contains Observable's. It's basically a "proxied" graph database. An object in JavaScript is a vertex in remote graph database. Getting a value of a property, if not primitive, is done through Observable and a HTTP request.

How can I effectively render such model in Angular 2?

One thing I could try is a 1:1 copy of the model class, only with normal reference instead of Observable, and filling that on return.

Also, my case is that I need a property of the object returned by the observable. In this, statsFilesByTypeJavaPercent is the Observable:

Java {{technologiesStats?.statsFilesByTypeJavaPercent?.quantity}} %

So how do I consume it?

1 Answer 1

4

Ok, got it... one can use AsyncPipe, with the syntax ... | async pipe in Angular 2 templates:

<li *ngFor="let item of items | async">{{item}}</li>

Pretty useful. Here is some tutorial on the topic.

Then if one needs a property of an object given by Observable, this is the syntax:

Java {{(technologiesStats.statsFilesByTypeJavaPercent | async)?.quantity}} %

Also I think I could create a special component for that would take the result as an input and show the .quantity.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.