Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to print value from observavle using async pipe

I am trying to print value from my observable class using async pipe, but so far with no luck.
I have following function, that returns observable class from my API call:

private getRecordType() {
   return this.getMyData().pipe(
      tap((res: Data) => {
         return res.recordType;
      }),
   );
}

Then I set to this.recordType the value that the getRecordType() function returns:

this.recordType = this.getRecordType();
console.log(this.recordType, 'RECORD_TYPE');
// returns Observable class

Then I try to print it in my template:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<b>{{ recordType | async }}</b>

However this only returns [object Object] in my template.
Any suggestions on what am I doing wrong?

Thank you in advance.

>Solution :

tap doesn’t change the emission of an Observable, so your tap in this case is doing nothing at all. The operator you’re looking for (to modify the emissions of an Observable) is map.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading