When working with observables, I often find myself using them like this:
...
const id = 1337;
this.service.getThing(id).subscribe(
suc => doSomething(suc.name),
err = doSomethingElse()
);
Lately, I've been utilizing the async pipe more frequently. This approach allows me to handle my observables in a cleaner way, as shown below.
thing$: Observable<Thing>;
...
ngOnInit(){
this.thing$ = this.service.getThing(1337);
}
However, I am curious if there's a way to declare an operation that can extract a specific field from the observable value when it is realized.
<div *ngIf="thing$ | async as thing>
{{thing.name}}
</div>
Instead of extracting the name manually, I wish to access only the name without additional steps.
I have attempted to explore the pipe(...) function in Angular thinking it might hold the solution. Unfortunately, my attempts were unsuccessful, and now I am unsure if that is the right approach.