In my app I have JSON data with date. I want to show the data in day vice i.e., Today, yesterday etc. and I have a status called completed and pending. I wrote the ion-segment, in that segment I have completed and pending. I want to show the completed data in completed segment and pending data in pending segment.
Json Data Example with what my app will work.
`[{
"day":"Today",
"name":"Sandra Adams",
"phno":8452514521,
"tests": "Ecma, Hcbc...",
"status":"pending"
}, {
"day":"Yesterday",
"name":"Nathan Jones",
"phno":8452457845,
"tests": "Ecma, Hcbc...",
"status":"completed"
}]`
答案 0 :(得分:0)
您应该使用Pipe
。
@Pipe({
name: 'anyPipe'
})
class AnyPipe implements PipeTransform {
public transform(values: any[], day: string) {
if (!values || !values.length) return [];
if (!day) return values;
return values.filter(v => v.day === day);
}
}
用法:
<list-item *ngFor="let item of (items | anyPipe:'Yesterday')"></list-item>