I am having this Multi-Select value change event where I would like to first filter selected object from the BehaviorSubject and then set the IsSelected prop to true and then for all remaining objects in the stream, set the IsSelected prop to false. Tried various things by looking online but have not found any solution. Please help.
Model:
export class SelectOptions {
DisplayName: string;
Value: string;
IsSelected: boolean;
}
Component:
selectOptions$: BehaviorSubject < SelectOptions[] > = new BehaviorSubject<SelectOptions[]>([]);
ngOnInit() {
this.reportService
.getFiltersData(this.fieldNameEnum.AicSuites)
.pipe(
tap((res) => {
console.log("--- data from api ---");
this.selectOptions$.next(res);
console.log(this.selectOptions$.value); = > this shows proper data
})
)
.subscribe();
}
OnValueChange event:
// here data is a array of selected items from the multi-select
// the goal here is to whenever user select any item, i need to set that object IsSelected prop to true and send it to Api later on.
// if user select the same item again, it's actually de-selectiong the item and (data) array will always have selected items. so i need to set IsSelected = false for all remaining items from Observable stream.
markAsSelected(data) {
data.forEach((selectedItem: SelectOptions) => {
this.selectOptions$
.pipe(
?? => no idea what to do here.tired several things but getting compilation error.
)
})}
Any help would be appreciated. Any other approach to doing the same thing in a better way is welcome.