Stworzyłem sobie typescriptową klasę:
class Cryptocurrency {
id: number;
symbol: string;
name: string;
websiteSlug: string;
links: Array<string>;
constructor(id: number, symbol: string, name: string, websiteSlug: string, links: Array<string>) {
this.id = id;
this.symbol = symbol;
this.name = name;
this.websiteSlug = websiteSlug;
this.links = links;
}
}
Pobieram sobie dane z zewnętrznego API (które wystawiam z drugiej aplikacji) i zapisuję sobie dane do Array<cryptocurrency>. Próbując wyświelić dane z tablicy, nie wyświetla się nic mimo, że dane fizycznie istnieją w tablicy (sprawdziłem debuggerem, prostym console.logiem, widzę też że tablica się uzupełnia - dlugosc tablicy wynosi 110). Plik html:
<ul>
<li *ngFor="let cryptocurrency of cryptocurrencies; let i = index">
{{i}} {{cryptocurrency.website_slug}}
<br>
</li>
</ul>
Klasa w ktorej pobieram i zapisuje dane do tablicy:
constructor(cryptocurrencyService: CurrenciesService) {
this.cryptocurrencyService = cryptocurrencyService;
this.cryptocurrencyService.getCurrencies().subscribe(resp => {
this.cryptocurrencies = resp.body;
});
}
Serwis:
getCurrencies(): Observable<HttpResponse<Array<Cryptocurrency>>> {
return this.http.get<Array<Cryptocurrency>>(this.url, {observe: 'response'});
}