Created
November 3, 2016 08:55
-
-
Save JonathanDn/3b8700caeebb8e9f6b311214cf015f11 to your computer and use it in GitHub Desktop.
Angular 2 Pipe to map a property : value mapping object into an array of key value pair objects
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
import { Pipe, PipeTransform } from '@angular/core'; | |
@Pipe({ | |
name: 'mapToKeyValue' | |
}) | |
export class MapToKeyValuePipe implements PipeTransform { | |
transform(obj: Object) { | |
let modifiedArray = []; | |
for (let key in obj) { | |
let value = obj[key]; | |
modifiedArray.push({key, value}); | |
} | |
return modifiedArray; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment