I have two components.
- Item List -- for displaying a list of items (parent)
- Item -- wrapper for a single item (child)
In the Item List component I basically create an observable using a service. The function getItems() returns an observable of items:
items$: Observable<Item[]>;
ngOnInit() {
this.items$ = this.service.getItems();
}
In the template I do ngFor with async pipe to display a list of items:
<div *ngFor="let item of items$ | async">
<card-item [item]="item"></card-item>
</div>
Now, in the Item component I have an option to remove that particular item from a firestore database:
@Input() item: Item;
removeItem() {
this.service.removeItem(this.item.id);
}
This operation takes some time so I wanted to remove it "locally" from the observable in the parent component.
I probably have to filter the observable in the parent component and somehow return a new filtered observable, but I don't know how can I manage this from the child component?
removeItem() {
// remove from firestore, but this can take some time
this.service.removeItem(this.item.id);
// meanwhile... remove it from the observable on parent
source.pipe(filter(item => item.id !== this.item.id)); // here is the problem I have
}
As you can see above I don't know how to "connect" to the observable and filter it.
The reason for that is when I want to animate the remove operation (like fade out), the item flashes. It's because the animation finishes earlier than the record is removed from the firestore.