【发布时间】:2018-04-13 14:04:27
【问题描述】:
我使用 angular 4 和 angularfire2 编写了一个组件,但我得到一个错误的回报,说 “ERROR TypeError: _this.memberEvents$.combineLatest is not a function”。
请参考以下代码并指出纠正方法。
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);
如何更正这条线。 有没有其他方法可以做到这一点。
}
});
});
});
}
}
【问题讨论】:
标签: angular rxjs angularfire2