I'm trying to build a component that access a service and return an observable with a list of objects to populate a table
My service has a function :
public getTranches(): Observable<Tranche[]> {
this.loadTranches(); //this calls the rest API to populate the variable _tranches
return this._tranches.asObservable(); // return variable <BehaviourSubject>_tranches asObservable
}
My Component consists of a table displaying the data through:
this.subscription = this.apiService
.getTranches()
.subscribe(
(data) => {
this.tranches = data;
}
);
html:
<ng-container *ngFor="let tranche of tranches">
// stuff
</ng-container>
Up util here everything works fine.
I added a input and click events to the table headers
//header example for sortby
<div (click)="this.filters.sortby = name"></div>
//input for filter
<input (keyup)="this.filters.search = $event.target.value" type="text">
and a variable filters to store that information
can you show me how to transform the filter variable in a observable and merge it to a single subscription to feed the table so I can perform the filtering and sorting on the component?
I've tried using filter as behaviourSubject and use combineLatest to merge them unsuccessfully if that is the way to do it can I see an example?