gpt4 book ai didi

javascript - 为项目列表正确声明 Observable

转载 作者:行者123 更新时间:2023-12-01 00:25:40 25 4
gpt4 key购买 nike

.html//根据错误问题出在HTML代码上

<ion-card *ngFor="let invitedEvent of invitedEvents">
<ion-card-content>
<img [src]="eventPhotoUrl$[invitedEvent.id] | async">
</ion-card-content>
</ion-card>

.ts

eventPhotoUrl$: { [id: string]: Observable<SafeResourceUrl> };

ngOnInit(){
this.eventPhotoUrl$[eventId] = this.photoService.eventPhotoObservable(eventId);
}

photoService.ts

private eventPhotoSubjects: { [id: string]: BehaviorSubject<SafeResourceUrl> } = {};


eventPhotoObservable(eventId: string): Observable<SafeResourceUrl> {

if (!this.eventPhotoSubjects[eventId]) {
const eventSubject: BehaviorSubject<SafeResourceUrl> = new BehaviorSubject<SafeResourceUrl>(PhotoPlaceholderPathConstant.EVENT_PHOTO_PLACEHOLDER_URL);
this.eventPhotoSubjects[eventId] = eventSubject;
this.afs.doc<ImagePathModel>(`eventDisplayPhotos/${eventId}`).valueChanges()
.subscribe(async () => {
const userIdToken: string = await this.auth.getUserIdToken();
const photoResponse: PhotoResponseModel = await this.getEventPhoto(userIdToken, eventId);
this.eventPhotoSubjects[eventId].next(this.sanitizer.bypassSecurityTrustResourceUrl(photoResponse.dataUrl));
});
}
return this.eventPhotoSubjects[eventId].asObservable();
}

运行时错误://s68VRWM3T7KZyrrurMyz = eventId

HomePage.html:66 ERROR TypeError: Cannot read property 's68VRWM3T7KZyrrurMyz' of undefined
at Object.eval [as updateRenderer] (HomePage.html:88)
at Object.debugUpdateRenderer [as updateRenderer] (core.js:39399)
at checkAndUpdateView (core.js:38382)
at callViewAction (core.js:38742)
at execEmbeddedViewsAction (core.js:38699)
at checkAndUpdateView (core.js:38377)
at callViewAction (core.js:38742)
at execEmbeddedViewsAction (core.js:38699)
at checkAndUpdateView (core.js:38377)
at callViewAction (core.js:38742)

你能告诉我如何为项目列表正确声明 Observable 吗?

最佳答案

您应该初始化eventPhotoUrl$:

eventPhotoUrl$: { [id: string]: Observable<SafeResourceUrl> } = {};

关于javascript - 为项目列表正确声明 Observable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59034553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com