In this Plunker I have this template :
<span *ngFor="let a of Articles">{{a}}</span>
This is the component class :
export class App
{
Articles: number[];
constructor()
{
this.getData();
}
simualteDb()
{
return new Promise((a, b) =>
{
setTimeout(function()
{
a(
{ // notice , an object ,not an array
data: [0, 1, 2]
});
}, 500)
});
}
async getData()
{
this.Articles = (await this.simualteDb()).data;
}
}
This does work and I do see 012
in the output. But I want to use the async
pipe.
So I want my template to be :
<span *ngFor="let a of Articles |async ">{{a}}</span>
But there is a problem.
Articles
is not an array. It is an object with data
prop which is the required array.
I can't do something like this :
<span *ngFor="let a of Articles.data |async ">{{a}}</span>
I've created another plunker which returns only an array :
and It does work with |async
.
Question:
Looking at my first code , How can I use the async pipe
while still resolving an object and not an array ?
{data: [0, 1, 2]}