I've been working on a function that returns an observable.
test(id: int): Observable<Group>{
this.http.get('test/').subscribe( (result:any) => {
resultingVal = Group.fromJson(result.group);
});
}
Right now, the function doesn't return anything, but my goal is to extract a specific property from a nested observable.
I am aiming for it to return returningVal, but I'm unsure of the best approach to achieve this nested value. Initially, I considered converting it into a promise, awaiting the result and then accessing the data. It worked, but it felt a bit clunky.
test(id: int): Observable<Group>{
let returningVal = null
let promise = this.http.get('test/').toPromise().then( result => {
returningVal = Group.fromJson(result.group);
});
return from(Promise.all([promise]).then( _ => returningVal));
}
Is using promises in this manner the most effective solution, or is there a more elegant alternative resembling the initial code snippet? I personally find this workaround with promises somewhat hacky.