I am a bit confused about how to get the key
and value
of an object in angular2 while using *ngFor
for iterating over the object. I know in angular 1.x there is a syntax like
ng-repeat="(key, value) in demo"
but I don't know how to do the same in angular2. I have tried something similar, without success:
<ul>
<li *ngFor='#key of demo'>{{key}}</li>
</ul>
demo = {
'key1': [{'key11':'value11'}, {'key12':'value12'}],
'key2': [{'key21':'value21'}, {'key22':'value22'}],
}
Here is a plnkr with my attempt: http://plnkr.co/edit/mIj619FncOpfdwrR0KeG?p=preview
How can I get key1
and key2
dynamically using *ngFor
? After searching extensively, I found the idea of using pipes but I don't know how to go about it.
Is there any inbuilt pipe for doing the same in angular2?
key, value
pair kind of syntax in angular2ngFor
, you should look at this answer – Pankaj ParkarPipe
for this.. – Pankaj Parkar