Skip to content

Instantly share code, notes, and snippets.

@thrixton
Forked from bombadillo/key-value.pipe.ts
Created December 21, 2017 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thrixton/531f75e93246e5d11827ba315b9bc799 to your computer and use it in GitHub Desktop.
Save thrixton/531f75e93246e5d11827ba315b9bc799 to your computer and use it in GitHub Desktop.
Angular 2 Key Value Pipe
import { Pipe, PipeTransform } from '@angular/core';
/*
* Enables the key/value pair of an item to be
* visible within an ngFor
* Usage:
* value of iteratable | keyValue
* Example:
* <ul>
* <li *ngFor='key of demo | keyValue'>
* Key: {{key.key}}, value: {{key.value}}
* </li>
* </ul>
*/
@Pipe({ name: 'keyValue' })
export class KeyValuePipe implements PipeTransform {
transform(value, args: string[]): any {
let keys = [];
for (let key in value) {
keys.push({ key: key, value: value[key]});
}
return keys;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment