Last active
November 25, 2019 15:24
-
-
Save NBprojekt/7c3aa23ea2c327ae4b430a9a928d8a86 to your computer and use it in GitHub Desktop.
Pipe for Typescript 2.4 enum which contain string initializers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage: | |
// <div *ngFor="let item of items | enum"> {{item.key}} | {{item.value}} </div> | |
import { Pipe, PipeTransform } from '@angular/core'; | |
@Pipe({ | |
name: 'enum' | |
}) | |
export class EnumPipe implements PipeTransform { | |
transform(object: Object): Array<{ key: string, value: string }> { | |
const keys = Object.keys(object); | |
return keys.map(key => ({ key, value: Object(object)[key] }) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment