I want to use a crypto coin api and i get data from server to my "_coins:coin[]" list. I tried "Console.log(_coins)" , console shows the array, also I can open this list at html page with "*ngFor" but i cant open at .ts file.
i tried this at component
public _coins:coin[]=[];
constructor(private _coinrepo:CoinRepository) {
this._coins=this._coinrepo.getMultiCoins(["BTC","ETH"]);
console.log(this._coins);
}
and at console:
Array []
0: Object { KEY: "BTC", BTC: 1, USD: 10018.38, … }
1: Object { KEY: "ETH", BTC: 0.02072, USD: 207.49, … }
length: 2
<prototype>: Array []
but i tried
public _coins:coin[]=[];
constructor(private _coinrepo:CoinRepository) {
this._coins=this._coinrepo.getMultiCoins(["BTC","ETH"]);
this._coins.forEach(i=>{
console.log(i);
});
}
and at console nothing. I also tried for loop, .find, .pop ... nothing work. i want to take data like :
for(let item of this._coins){
_btc=item.BTC;
_usd=item.USD;
}
Please help me.. codes are here : https://stackblitz.com/edit/angular-ejrojd?embed=1
this._coinrepo.getMultiCoins(["BTC","ETH"])- Is this returns an observable? or plain array? If it returns an observable then you need to subscribe. In HTML it is working because you might be usingasyncpipe. Also Is there any error on console?