'Source of forkjoin() not recognized as function
I'm using a ForkJoin to wait on 3 objects. Calling their getters inside the fork join seems not to work, giving the error seen below. The same method is called multiple times throughout the project, but does not seem to work in side a ForkJoin. There are no compile errors, the error is given when the code is run. Can anybody explain to me why?
It is my first time using ForkJoin and have been using the RXJS documentation to learn.
MailService / mail.service.ts:
import {HttpClient,HttpErrorResponse,HttpHeaders} from '@angular/common/http';
import { Injectable } from '@angular/core';
import {forkJoin,Observable,throwError,} from 'rxjs';
import { catchError, tap } from 'rxjs/operators';
import { environment } from 'src/environments/environment';
import { Booking } from './booking/booking.model';
import { Camper } from './camper/camper.model';
import { User } from 'src/app/modules/user/user.model';
import { UserDataService } from 'src/app/modules/user/user.data.service';
import { CamperDataService } from 'src/app/modules/camper/camper.data.service';
import { BookingDataService } from 'src/app/booking/booking.data.service';
@Injectable({
providedIn: 'root',
})
export class MailService {
public headers = new HttpHeaders({'Authorization': environment.apiKey});
constructor(
private http: HttpClient,
private _userDataService: UserDataService,
private _bookingDataService: BookingDataService,
private _camperDataService: CamperDataService
) {}
sendMailNewBooking(booking: Booking) {
console.log('start mail service');
var body;
forkJoin({
camper: this._camperDataService.getCamper$(booking.camperId),
user: this._userDataService.getUser$(booking.travellerId),
auth: this._userDataService.getAuthZeroData$(booking.travellerId),
}).subscribe({
next: ({ camper, user, auth }) => {
body = {
booking: booking,
camper: camper,
user: user,
email: auth.email,
};
},
error: (err) => console.error(err),
});
console.log('body =>');
console.log(body);
var call = this.http
.post(`${environment.apiUrl}/mail/newbooking/`, body, {
headers: this.headers,
})
.pipe(tap(console.log), catchError(this.handleError));
return call;
}
}
UserDataService / user.data.service:
import {HttpClient,HttpErrorResponse,HttpHeaders,HttpParams} from '@angular/common/http';
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable, throwError } from 'rxjs';
import { User } from './user.model';
import { catchError, map, switchMap, tap } from 'rxjs/operators';
import { environment } from 'src/environments/environment';
import { Auth0Management } from 'src/app/auth0-management.model';
import { MailService } from 'src/app/modules/mail.service';
@Injectable({
providedIn: 'root',
})
export class UserDataService {
private _reloadUsers$ = new BehaviorSubject<boolean>(true);
public headers = new HttpHeaders({'Authorization': environment.apiKey});
constructor(private http: HttpClient,private _mailService: MailService ) {}
getUser$(this: UserDataService, id: string): Observable<User> {
console.log("User id? -> " + id);
return this.http
.get(`${environment.apiUrl}/users/${id}`, {headers: this.headers})
.pipe(tap(console.log), catchError(this.handleError), map(User.fromJSON));
}
}
The mail service method is called as such:
this._bookingDataService.addNewBooking(createdBooking)
.subscribe((bkn: Booking) => {
console.log('sending mail new booking');
this._mailService.sendMailNewBooking(bkn);
}
It is on the page where the booking gets made.
Output:
main.js:1 start mail service
main.js:1 ERROR TypeError: this._userDataService.getUser$ is not a function
at n.sendMailNewBooking (main.js:1:156389)
at Object.next (main.js:1:913301)
at Me.next (main.js:1:1219971)
at Ee._next (main.js:1:1219651)
at Ee.next (main.js:1:1219345)
at se._next (main.js:1:1219651)
at se.next (main.js:1:1219345)
at o.subscribe.h (main.js:1:56772)
at se._next (main.js:1:1226106)
at se.next (main.js:1:1219345)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
