I have developed a method to create an observable
by designing a class that maintains the object and class observable's next()
whenever there is an assignment.
class myObsClass{
private sub;
public obj;
public obj$;
constructor(){
this.sub = new Subject<any>();
this.obj = new Object();
this.obj$ = this.sub.asObservable();
}
set object (value){
this.obj = value;
this.sub.next(this.obj);
}
}
In my service, I create an instance of this class like this:
public myObs = new myObsClass();
Then, in the component, I subscribe to it in the following way:
this.service.myObs.obj$.subscribe(data => {
// do something with the data
});
Initially, everything works fine. However, after being idle for about 10 or 20 minutes, the subscribe function doesn't get called at all.
What could be causing this issue? Is the approach I am using correct?
Note: The provided code is for explanation purposes only and may not function correctly if copied and pasted directly.