-2
 isEnabledDeleteCourtChanged$: { [courtId: string]: Observable<boolean> };

 private isEnabledDeleteCourtSubject$: { [courtId: string]: BehaviorSubject<boolean> };

 private initialize(): void {

  this.isEnabledDeleteCourtSubject$= new BehaviorSubject<boolean>(false); // here has problem
  this.isEnabledDeleteCourtChanged$ = this.isEnabledDeleteCourtSubject$.asObservable(); // here has problem
}

 setIsEnabledDeleteCourt(courtId: string, isEnabled: boolean): void {

    this.isEnabledDeleteCourtSubject$[courtId].next(isEnabled); // here has problem
}

上面的代码不起作用。它说Cannot read property 'next' of undefined。那么你能告诉我如何正确构造带有 Observable 的 Dictionary 对象吗?初始化也不行?IEinitialize()

4

2 回答 2

0

在这里,我们不能在没有courtId. 所以这对我有用。

服务.ts

isEnabledRevertToGroupChanged$: { [courtId: string]: Observable<boolean> } = {};

private isEnabledRevertToGroupSubject$: { [courtId: string]: BehaviorSubject<boolean> } = {};

setIsEnabledDeleteCourt(courtId: string, isEnabled: boolean): void {

        this.isEnabledDeleteCourtSubject$[courtId] = new BehaviorSubject<boolean>(false);

        this.isEnabledDeleteCourtSubject$[courtId].next(isEnabled);

        this.isEnabledDeleteCourtChanged$[courtId] = this.isEnabledDeleteCourtSubject$[courtId].asObservable();
    }

html

 <ion-col *ngIf="queueDataService?.isEnabledDeleteCourtChanged$[queue?.qId] | async">
 </ion-col>
于 2021-06-09T08:58:46.747 回答
0

看看它的对象,isEnabledDeleteCourtSubject$你真的想要它末尾的 $ - 是否需要 $?设置它时你isEnabledDeleteCourtSubject$=没有空间 - 也许是未定义的问题?

于 2021-06-08T18:51:09.953 回答