-
-
Save icfantv/4ca15ce0b880b44f718a11abb8ea02f6 to your computer and use it in GitHub Desktop.
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
from @amcdnl | |
import { Pipe } from 'angular2/core.js'; | |
/** | |
* Map to Iteratble Pipe | |
* | |
* It accepts Objects and [Maps](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) | |
* | |
* Example: | |
* | |
* <div *ngFor="#keyValuePair of someObject | mapToIterable"> | |
* key {{keyValuePair.key}} and value {{keyValuePair.value}} | |
* </div> | |
* | |
*/ | |
@Pipe({ name: 'mapToIterable' }) | |
export class MapToIterable { | |
transform(value) { | |
let result = []; | |
if(value.entries) { | |
for (var [key, value] of value.entries()) { | |
result.push({ key, value }); | |
} | |
} else { | |
for(let key in value) { | |
result.push({ key, value: value[key] }); | |
} | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from @ocomb