Assume a simple app.component setup where html has something along the lines of.
HTML
<div *ngIf="testObservable$ | async as testObservable">
hello world
</div>
TS
testObservable$: Observable<any>;
_testBehaviourSubject$ = new BehaviourSubject<any>(null);
constructor(public http: HttpClient) {
this.testObservable$ = this._testBehaviourSubject$.asObservable();
}
getData() {
return this.http.get(someApiURL).pipe(tap((e:any) => this._testBehaviourSubject$.next(any));
}
What is the best way to subscribe to getData() to update the BehaviourSubject IF it is null.
Essentially flow would be
listen for BehaviourSubject data as BSDATA
Event 1
BSDATA is null
do getData()
Event 2
BSDATA is not null
display 'Hello World'
Ideally I'd like to leverage the async pipe as opposed to triggering subscribe event manually. Advice appreciated.