0

Receiving this error in console:

Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.

services.ts

      private url = "https://api.iextrading.com/1.0/stock/market/batch?symbols=SNAP,fb,AIG%2b,GOOG,AAPL,AMZN&types=quote";

      constructor(private http: HttpClient) {}

      getCID(): Observable<any> {
        return this.http.get<any>(this.url);
      }

component.ts

      ngOnInit() {
        this.svc.getCID().subscribe(data => {
          this.cidData = data;
          console.log(data);
        });

component.html

    <div *ngIf="cidData">
      <ul>
        <li *ngFor="let x of cidData">
          <a routerLink="/companydetails/{{x.symbol}}">{{x.symbol}}</a>

API call gives

    {"GOOG":{"quote":{"symbol":"GOOG","companyName":"Alphabet Inc."}}, "SNAP":{etc...}

I think the issue is that cidData is not an array, but I'm not really sure how to return it as an array

2 Answers 2

2

If your are using angular version 6 then you can use the built-in pipe keyvalue to iterate through objects

 <li *ngFor="let x of cidData | keyvalue">
      <a routerLink="/companydetails/{{x.value.quote.symbol}}">{{x.value.quote.symbol}}</a>
Sign up to request clarification or add additional context in comments.

Comments

0

to turn your object into an array by Object.values(obj), you can see here

// object with your example here
    ngOnInit() {
        this.svc.getCID().subscribe(data => {
            this.cidData = data;
            let array = 
            Object.values(this.cidData.GOOD) 
            // here you have an array    
            console.log(array);
   });

1 Comment

normally with a single object, otherwise it must be a table the response if there is more object

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.