method(): Observable<boolean> {
if (sessionId === '')
return false;
return this._http.get('sessionId=' + sessionId).map(res=> {
if (res.status === "success") {
return true;
}
return false;
});
}
This will give an error:
Type 'boolean' is not assignable to type 'Observable'.
The reason is becuase
method(): Observable<boolean> {
if (sessionId === '')
return false; // <<< obviously not an observable
method(): Observable<boolean> {
if (sessionId === '')
return Observable.of(false);
}
return this._http.get('sessionId=' + sessionId).map(res=> {
if (res.status === "success") {
return true;
}
return false;
});
}
import { Observable, of as observableOf } from 'rxjs'; // since RxJs 6
method(): Observable<boolean> {
if (sessionId === '') {
return observableOf(false);
}
return this._http.get('sessionId=' + sessionId).map(res=> {
if (res.status === "success") {
return true;
}
return false;
});
}