I can't get the addReservation function to return any value.
in reservations.page.ts it returns an empty array when I log to the console.
userReservations: Reservation[];
private resSubscription: Subscription;
constructor(private resService: ReservationsService) { }
ngOnInit() {
this.resSubscription =
this.resService.reservations.subscribe(reservations => {
console.log('reservations...', reservations);
this.userReservations = reservations;
});
}
below is reservations.service.ts I can't get the reservations in the return statement to log any value so I'm guessing the issue may be there.
export class ReservationsService {
private _reservations = new BehaviorSubject<Reservation[]>([]);
constructor(private authentication: AuthenticationService) { }
// return the parking space reservations
get reservations() {
return this._reservations.asObservable();
}
// create a reservation
addReservation(
parkingSpaceId: string,
parkingSpaceTitle: string,
url: string,
firstName: string,
lastName: string,
reservedDayCount: number,
reservedFrom: Date,
reservedTo: Date
) {
const newReservation = new Reservation(
Math.random().toString(),
parkingSpaceId,
this.authentication.userId,
parkingSpaceTitle,
url,
firstName,
lastName,
reservedDayCount,
reservedFrom,
reservedTo
);
return this.reservations.pipe(
take(1),
tap(reservations => {
console.log('return reservations...', reservations);
this._reservations.next(reservations.concat(newReservation));
})
);
}
}
this.resService.reservationsinreservations.page.tsright? using this.reservations I get property does not exist.