I’ve got a bit muddled with this, but basically I have a few different elements (jobs,tasks,versions) so if I am on the ‘job’ page I load that specific job from Mongo from my job service, e.g.:
getJobById(id) {
this.subscription = this.subscribe('jobs', () => {
this.job = Jobs.findOne({"_id":id});
this.job$.next(Jobs.findOne({"_id":id}));
}, true);
}
But I have another component which loads a form for these various elements, and its not always linked to the page your on. So if i’m on the job page and I then load up the job form I want to get the job that was last called by the job service. In my service I tried subscribing to it, but this doesn’t seem to return anything:
this.subscription = this._jobService.job$.subscribe(job => {
if (!job) return;
this.job = job;
});
Thats why in the snippet above I tried storing a local copy of ‘job’ in the service then when I load the form I was calling another function to update the observable with that local variable:
refresh() {
console.log('refreshing ' + this.job);
this.job$.next(this.job);
}
But ‘this.job’ is returning undefined… Have I missed something obvious? And/or is there a really simple solution to this?