I need to pass data from one component to another but I'm having a hard time doing so.
I have an Observable
that I need to pass as Subject
which is another Observable. How do I do that?
The way I currently have is not working as it gets in the target component undefined
.
This is what I have:
card.component.ts (where it all begins)
showBox(studentID) {
const airportPickup = this.studentService.getCurrentStudents().pipe(
map(snaps => {
const student = snaps.find( s => s.studentID === studentID );
return {
requirePickup: student.pickup,
whopickup: student.whoPickup
};
})
);
this.studentService.airportPickupDropoff.next(airportPickup);
}
If I console.log()
the airportPickup
I get the object. No issues. The problem is when I get it in the other component, I get it as undefined
.
flight-info.component.ts (the target)
getAirportPickup() {
this.studentService.airportPickupDropoff.subscribe(
(apdata) => {
this.airportPickupDropoff = apdata;
},
(e) => alert(e)
);
}
The service I have this:
airportPickupDropoff = new Subject<any>();