I'm currently working with rxjs in combination with Angular.
Within my codebase, I have a class that includes a public property which is of type observable.
Another class within the application needs to subscribe to this particular observable.
The issue arises when the observable starts off as null and is only initialized after a slight delay.
To temporarily address this problem, I resorted to using an unsightly setTimeout function.
What are some cleaner solutions that can be implemented?
class HasAnObservable {
observableProp: Observable<any> = null;
constructor() {
// This method is responsible for initializing the Observable
this.initObservableProp();
}
class UsesTheObservable {
constructor(private readonly hasAnObservable: HasAnObservable)
{
this._useTheObservable()
}
private _useTheObservable() {
// The main issue lies in the fact that observableProp begins as null
this.hasAnObservable.observableProp.subscribe()
}
}