我使用angular 4和angularfire2编写了一个组件,我得到一个错误,回复说“ERROR TypeError:_this.memberEvents $ .combineLatest不是函数”。
请参阅以下代码并指出纠正方法。
import { Observable } from 'rxjs/Observable';
import { MemberService } from './../../member.service';
import { ClubService } from './../../club.service';
import { ActivatedRoute } from '@angular/router';
import { EventService } from './../../event.service';
import { Component, OnInit, OnChanges, OnDestroy } from '@angular/core';
import { select } from 'ng2-redux';
import 'rxjs/add/operator/take';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/observable/empty'
import 'rxjs/add/operator/takeUntil';
import 'rxjs/add/observable/combineLatest';
import 'rxjs/add/observable/of';
import { Subject } from 'rxjs';
@Component({
selector: 'member-favorite',
templateUrl: './member-favorite.component.html',
styleUrls: ['./member-favorite.component.css']
})
export class MemberFavoriteComponent implements OnInit, OnDestroy {
userId;
favoriteEvents$;
memberEvents$ = Observable.of([]);
id;
private ngClubsUnsubscribe$ = new Subject();
constructor(private route: ActivatedRoute,
private eventService: EventService,
private clubService: ClubService,
private memberService: MemberService) {
this.userId = localStorage.getItem('userId');
this.id = this.route.snapshot.paramMap.get('id');
}
ngOnInit() {
this.getMemberEvents();
}
ngOnDestroy() {
this.ngClubsUnsubscribe$.next();
this.ngClubsUnsubscribe$.complete();
}
getMemberEvents() {
this.clubService.getActiveClubs().takeUntil(this.ngClubsUnsubscribe$)
.subscribe(clubs => {
clubs.map(c => {
this.memberService.isMember(c.id, this.userId)
.take(1)
.subscribe(res => {
if(res && res === true) {
console.log("user is a member of club ", c.clubname);
let clubEvents = this.eventService.getForthCommingEventsOfClub(c.id);
this.memberEvents$.combineLatest(clubEvents);
如何更正此行。 还有其他办法吗?
}
});
});
});
}
}
答案 0 :(得分:0)
您可以直接从Observable
调用combineLatest。
Ex:Observable.combineLatest(..., ...)
。
如果您想根据示例添加其他流,则可以使用withLatestFrom
运算符:
this.memberEvents$.withLatestFrom(clubEvents);