I have array like this
this.location={"asdsad":{"asdsad":"qweqwe"}};
<li ng-repeat="(key, value) in location">
{{value | json}}
</li>
Tried to print in html like above but it's not working.
I have array like this
this.location={"asdsad":{"asdsad":"qweqwe"}};
<li ng-repeat="(key, value) in location">
{{value | json}}
</li>
Tried to print in html like above but it's not working.
If you're using Angular 6.1.0, you can use the keyvalue pipe:
<div *ngFor="let item of location | keyvalue">
<p>{{ item.value | json }}</p>
</div>
Not originally my answer, found it here: access key and value of object using *ngFor.
Try to use Object.keys
in the template and use it in *ngFor
instead of ng-repeat
.
objectKeys = Object.keys;
location = {'asdsad': {'asdsad': 'qweqwe'}};
<li *ngFor="let key of objectKeys(location)">
{{key + ' : ' + location[key]}}
</li>
This code is work for me. i'm not sure it's best way to solve your problem.
component:
location = {asdsad :{asdsad:"qweqwe"}};
objectKeys = Object.keys;
Html:
<li *ngFor="let key of objectKeys(location)">
{{key + ' ' + (location[key].asdsad | json)}}
</li>