Key (Pipe)
This pipe can be used for "for loops", in the case of an array with non-numeric indexes.
It returns the key and the value(s). In the example below the {{item.key}}
contains the index value
and the {{item.value}}
contains the value(s).
When the value is an object with name and label, you get them with {{item.value.name}}
and {{item.value.label}}
.
Examples
HTML file
<ul>
<li *ngFor="let item of array | dspKey">
{{item.key}}: {{item.value}}
</li>
</ul>
Typescript file
array = [];
this.array['index-1'] = 'Value in index 1';
this.array['index-2'] = 'Value in index 2';
this.array['index-3'] = 'Value in index 3';
Last update: 2021-08-13