【发布时间】:2019-11-20 14:28:24
【问题描述】:
我需要将数据从一个组件传递到另一个组件,但我很难做到。
我有一个Observable,我需要将其传递为Subject,这是另一个Observable。我怎么做?
我目前的方式在 目标组件 undefined 中无法正常工作。
这就是我所拥有的:
card.component.ts (一切从这里开始)
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);
}
如果我 console.log() airportPickup 我得到对象。没有问题。问题是当我在另一个组件中得到它时,我得到的是undefined。
flight-info.component.ts (目标)
getAirportPickup() {
this.studentService.airportPickupDropoff.subscribe(
(apdata) => {
this.airportPickupDropoff = apdata;
},
(e) => alert(e)
);
}
服务我有这个:
airportPickupDropoff = new Subject<any>();
【问题讨论】:
标签: angular rxjs angular2-observables rxjs-observables