I am returning multiple CartItem
objects from my Django backend that have a delivery_date
field. On the Angular8 frontend I want to break up all the CartItem
objects by delivery_date
and display them on the browser, separated by date headings.
I thought that I could just do this in in the html tag but I cant seem to get the syntax correct. My other approach was to write a my own filter? I see a lot of AngularJS info on this but not so much Angular 8. I also thought I could use the pipe or map function, but i dont think you can use multiple of those which i would need because i want to break up to multiple dates.
component.ts
orders;
filterargs = {delivery_date: '2020-06-12'};
ngOnInit() {
this.getrestaurantorders()
}
getrestaurantorders(id){
this.orderservice.restaurantorders(id).subscribe(
x => this.orders = x
)
}
}
latest html attempt
<h1>Date1</h1>
<div *ngFor="let order of orders | filter: {delivery_date: '2020-06-12'}">
(also tried this: <div *ngFor="let order of orders | filter: filterargs">)
Order:{{order.xxx}}<br>
</div>
<h1>Date2</h1>
<div *ngFor="let order of orders | filter: {delivery_date: '2020-06-13'}">
(also tried this: <div *ngFor="let order of orders | filter: filterargs">)
Order:{{order.xxx}}<br>
</div>
With the latest html tag filter attempt i get Error: The pipe 'filter' could not be found!
, which makes me think i need to create a whole pipe class. Seems like there should be an easy filter that i am missing.
EDIT:
getrestaurantorders(id){
this.orderservice.restaurantorders(id).subscribe(
x => this.orders = x,
)
this.filterday()
}
filterday(){
this.orders = this.orders.filter(order => order.delivery_date == '2020-06-12')
}
}
Adding filterday()
which should filter through the CartItems
. Since i need to wait for the observable to finish first, i was going to try this SO approach:
Create and then subscribe to a Subject