fix item select
This commit is contained in:
parent
5d6e3053fe
commit
4621e95481
@ -99,7 +99,7 @@ export class ListingService<E extends IListable> {
|
||||
isSelected$(entity: E): Observable<boolean> {
|
||||
return this._selected$.pipe(
|
||||
any(selectedId => selectedId === entity.id),
|
||||
shareDistinctLast(),
|
||||
shareLast(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import { ChangeDetectionStrategy, Component, forwardRef, Inject, Input, OnInit } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ChangeDetectionStrategy, Component, forwardRef, Inject, Input, OnChanges } from '@angular/core';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { ListingComponent } from '../..';
|
||||
import { IListable } from '../../models';
|
||||
import { ListingService } from '../../services';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
selector: 'iqser-table-item',
|
||||
@ -10,18 +11,21 @@ import { ListingService } from '../../services';
|
||||
styleUrls: ['./table-item.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class TableItemComponent<T extends IListable> implements OnInit {
|
||||
export class TableItemComponent<T extends IListable> implements OnChanges {
|
||||
@Input() entity!: T;
|
||||
@Input() selectionEnabled = false;
|
||||
|
||||
isSelected$!: Observable<boolean>;
|
||||
private readonly _entityChanged$ = new BehaviorSubject<T>(this.entity);
|
||||
|
||||
constructor(
|
||||
@Inject(forwardRef(() => ListingComponent)) readonly listingComponent: ListingComponent<T>,
|
||||
readonly listingService: ListingService<T>,
|
||||
) {}
|
||||
) {
|
||||
this.isSelected$ = this._entityChanged$.pipe(switchMap(entity => this.listingService.isSelected$(entity)));
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.isSelected$ = this.listingService.isSelected$(this.entity);
|
||||
ngOnChanges(): void {
|
||||
this._entityChanged$.next(this.entity);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user