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