Created
June 8, 2016 17:48
-
-
Save StephenFluin/5bea382b314979942c1748555c500271 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
import { Pipe, PipeTransform } from '@angular/core'; | |
@Pipe({name: 'reFirebase'}) | |
export class ValuesPipe implements PipeTransform { | |
transform(value: any, args?: any[]): any[] { | |
let keys = Object.keys(value), | |
output = []; | |
keys.forEach(key => { | |
let arrayItem = value[key]; | |
if(key != "$key") { | |
arrayItem.$key = key; | |
output.push(arrayItem); | |
} | |
}); | |
return output; | |
} | |
} |
Sample usage:
<div *ngFor="let category of data | async">
<h3>{{category.$key}}</h3>
<div *ngFor="let sub of category | reFirebase"><h4>{{sub.$key}}</h4>
<div *ngFor="let resource of sub.resources | reFirebase">
<a target="_blank" [href]="resource.url">{{resource.title}}</a> <span *ngIf="resource.rev">Public!</span></div>
</div>
</div>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looking to iterate through nested Firebase data with AngularFire2 from within your template? reFirebase can help!