Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为项目列表正确声明可观察_Javascript_Angular_Typescript_Rxjs_Ionic4 - Fatal编程技术网

Javascript 为项目列表正确声明可观察

Javascript 为项目列表正确声明可观察,javascript,angular,typescript,rxjs,ionic4,Javascript,Angular,Typescript,Rxjs,Ionic4,.html//根据错误,问题在于html代码 <ion-card *ngFor="let invitedEvent of invitedEvents"> <ion-card-content> <img [src]="eventPhotoUrl$[invitedEvent.id] | async"> </ion-card-content> </ion-card> 您能告诉我如何为项目列表正确

.html//根据错误,问题在于html代码

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

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

您应该初始化
eventPhotoUrl$

eventPhotoUrl$:{[id:string]:可观察的}={};

您应该初始化
eventPhotoUrl$

eventPhotoUrl$:{[id:string]:可观察的}={};

看起来eventPhotoUrl$未定义。在没有看到代码的情况下,我猜您没有初始化eventPhotoSubjects,是吗@ParrapbanzZ是的,请查看更新。也许您应该初始化
eventPhotoUrl$
eventPhotoUrl$={}
@ParrapbanzZ完成。请看。@AndreiGătej你说得对。这么重要的提示。我希望你能把它作为一个答案。谢谢。看起来eventPhotoUrl$未定义。在没有看到代码的情况下,我猜您没有初始化eventPhotoSubjects,是吗@ParrapbanzZ是的,请查看更新。也许您应该初始化
eventPhotoUrl$
eventPhotoUrl$={}
@ParrapbanzZ完成。请看。@AndreiGătej你说得对。这么重要的提示。我希望你能把它作为一个答案。谢谢
eventPhotoUrl$: { [id: string]: Observable<SafeResourceUrl> };

ngOnInit(){
 this.eventPhotoUrl$[eventId] = this.photoService.eventPhotoObservable(eventId);
}
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();
  }
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)