There is an if clause in my code that checks for the presence of the cordova object in the window global object. If cordova is present, it will make a http request and return the default angular 2 http observable.
If the application is in a web context where cordova does not exist, the function should not do anything.
However, in order to subscribe to the observable, I need to ensure I am returning an observable or else I will encounter a 'can't subscribe to null' error. Currently, I am using Observable.empty() as a solution,
but I wonder if there is a safer or more elegant approach. Thank you!
public init():Observable<Response>{
if(window.cordova){
return this.http.get(...)
} else {
return Observable.empty()
}
}
This is the code snippet, and I noticed that I need to change something to make it work... Is there a way to return Observable instead?