Angular 4: not able to iterate over an array

0 votes

Im trying to iterate over an array but the dom is displaying [ object Object]. In other threads some people recommended to use Stringify and then it display the info but I can't iterate over a string. 

Here is my code:

html

<div *ngFor="let price of prices">
    {{prices}}
    </div>

service.ts

import { Injectable } from '@angular/core';
import { Http, Headers, Response } from '@angular/http';
import 'rxjs/add/operator/toPromise';
import {Observable} from "rxjs";
import 'rxjs/Rx';
import 'rxjs/add/operator/catch';
import { MarketViewModel } from '../comprarmonedas/datosmoneda'


@Injectable()
export class BittrexService {

  constructor(private http: Http, private marketModel : MarketViewModel) { }

  public getPrices() :Observable<MarketViewModel> {
    return this.http.get('https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-zec')
    .map((response: Response) => response.json());
  }

}


interface

export class MarketViewModel {
  public success : boolean;
  public message : string;
  public result : MarketListObject[];
}

export class MarketListObject {
    public MarketName : string;
    public High : number;
    public Low : number;
    public Volume : number;
    public Last : number;
    public BaseVolume : number;
    public TimeStamp : number;
    public Bid : number;
    public Ask : number;
    public OpenBuyOrders : number;
    public OpenSellOrders : number;
    public PrevDay : number;
    public Created : number; 

}

component.ts

import { Component, OnInit } from '@angular/core';
import { Http, Response, Headers } from '@angular/http';
import { BittrexService } from '../../bittrex/bittrex.service';
import {Observable} from "rxjs";

@Component({
  selector: 'app-comprarzec',
  templateUrl: './comprarzec.component.html',
  styleUrls: ['./comprarzec.component.scss']
})
export class ComprarzecComponent implements OnInit {

  private prices = [];

  constructor(private bittrexService: BittrexService) {
    this.bittrexService = bittrexService;
  }

ngOnInit(){
  this.bittrexService.getPrices()
  .subscribe(
    data => this.prices = data.result
  );
}
 }
Sep 3, 2018 in Blockchain by slayer
• 29,040 points
41 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Replace this :

<div *ngFor="let price of prices">
    High : {{price.High}} , Low : {{price.Low}}
</div>

You were trying to print array of obejcts prices, It should be price not prices

    High : {{price.High}} , Low : {{price.Low}}

Like this you can access any of the given values :

{
      "MarketName": "BTC-ZEC",
      "High": 0.16290000,
      "Low": 0.13087156,
      "Volume": 12760.98721068,
      "Last": 0.15650003,
      "BaseVolume": 1908.20341779,
      "TimeStamp": "2017-06-14T19:15:25.57",
      "Bid": 0.15650003,
      "Ask": 0.15786551,
      "OpenBuyOrders": 1130,
      "OpenSellOrders": 1257,
      "PrevDay": 0.13380000,
      "Created": "2016-10-28T17:13:10.833"
    }
answered Sep 3, 2018 by digger
• 27,620 points

Related Questions In Blockchain

0 votes
1 answer

I am not able to change array elements globally

Remove the constant modifier from getArray(). constant functions do not write state ...READ MORE

answered Oct 9, 2018 in Blockchain by Omkar
• 65,850 points
13 views
0 votes
1 answer

Not Able to register a user with Hyperledger-Fabric v1.1 preview

The error: "Certificate not found with AKI 'e729224e8b3f31784c8a93c5b8ef6f4c1c91d9e6e577c45c33163609fe40011' ...READ MORE

answered Jun 16, 2018 in Blockchain by charlie_brown
• 7,710 points
292 views
0 votes
1 answer
0 votes
1 answer

Windows not able to recognize Monax command

You probably know this already but support ...READ MORE

answered Jun 21, 2018 in Blockchain by Johnathon
• 9,050 points
21 views
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by ariaholic
• 7,320 points
43 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
65 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Not able to execute a deployed contract?

The problem is that you are not ...READ MORE

answered Jul 29, 2018 in Blockchain by digger
• 27,620 points
17 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.