The problem is that data is captured inside the observable and I can just console log it. I want to return that value and console.log or whatever from different file by calling the function in which it resides.
Looks like you are looking for a "current value" getter inside an observable, when it emits and after an emission.
Subject
and Observable
doesn't have such a thing. When a value is emitted, it is passed to its subscribers and the Observable
is done with it.
You may use BehaviorSubject
which stores the last emitted value and emits it immediately to new subscribers.
It also has a getValue()
method to get the current value;
Further Reading: