I have a component like
export class InspectionComponent {
@Input()
inspections: Inspections[];
}
I'd like to group the inspections by a date property. Do I use or pipe or is there a way to transform the list in the component? I'm thinking an observable, but I can't figure out if it's possible to observe a component input?
Basically what I'd like to write is something like (I know this doesn't make sense, but it shows the point)
export class InspectionComponent implement OnInit {
@Input()
inspections: Inspection[];
groups: { date: Date, inspections: Inspection[] };
ngOnInit() {
inspections.groupBy(...).subscribe(groups => this.groups = groups);
}
}
I've read on the Angular Docs on Pipes that it is strongly recommended to do filtering and sorting in the component logic.
inspectionsdata come from? Where, when, how often do you want to transform?inspectionslist everytime it changes, and preferably in the component logic.inspectionsis not an observable. Would the input then have the typeObservable<Inspection[]>and then I need to change the parent component to handle an observable instead of a regular array? It seems a little convoluted, I'd like it better if theInspectionComponentcould just take a regular list and group it.