I am trying to Learn Async Pipe and how to use them. however I have an issue with using Async Pipe in the following case;
I am using this fake/dummy API Cat API I can't figure how to retrieve the Object Data inside the observable value.
TS Code
import { Component, OnInit } from '@angular/core';
import { HttpService } from '../services/http/http.service';
import { facts } from '../interfaces/facts';
import { Observable } from 'rxjs';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit{
facts$! : Observable<facts[]>
constructor(private client : HttpService){
}
ngOnInit(): void {
this.facts$ = this.client.getListFacts(25, 5)
}
}
Interface
export interface facts {
fact : string,
length : number
}
HTML
<div class='home'>
<ul style="margin: 0 0 0 0">
<li *ngFor="let fact of (facts$ | async)">{{fact.fact}}</li>
</ul>
</div>
HTTP Service
getListFacts(length : number, limit : number) : Observable<facts[]>{
return this.client.get<facts[]>(`https://catfact.ninja/facts?max_length=${length}&limit=${limit}`)
I have tried to async pipe results, fact of facts list inside the HTML code, however it renders nothing