Angular12 get API making table data not showing


So I’m trying to make a table that use ngFor for every data in the API. I tried a tutorial in Youtube video and it is working fine. Now I’m trying it with the API given to me, but the problem is the data is not coming out in the table

<!-- Main content -->
<section class="content">
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-12">
        <!-- TABLE: LATEST ORDERS -->
        <div class="card">
          <div class="card-header border-transparent">
            <h3 class="card-title">Latest Orders</h3>

            <div class="card-tools">
              <button type="button" class="btn btn-tool" data-card-widget="collapse">
                <i class="fas fa-minus"></i>
              <button type="button" class="btn btn-tool" data-card-widget="remove">
                <i class="fas fa-times"></i>
          <!-- /.card-header -->
          <div class="card-body p-0">
            <div class="table-responsive">
              <table class="table m-0">
                  <th>Order ID</th>
                  <td><a href="pages/examples/invoice.html">OR9842</a></td>
                  <td>Call of Duty IV</td>
                  <td><span class="badge badge-success">Shipped</span></td>
                    <div class="sparkbar" data-color="#00a65a" data-height="20">90,80,90,-70,61,-83,63</div>
                <tr *ngFor="let campaign of campaigns | async">
                  <td><a href="pages/examples/invoice.html">{{}}</a></td>
                  <td><span class="badge badge-warning">Pending</span></td>
                    <div class="sparkbar" data-color="#f39c12" data-height="20">90,80,-90,70,61,-83,68</div>
            <!-- /.table-responsive -->
          <!-- /.card-body -->
          <div class="card-footer clearfix">

          <!-- /.card-footer -->
        <!-- /.card -->
      <!-- /.col -->
    </div> <!-- /.row -->


import { Component, OnInit } from '@angular/core';
import { GetServiceService } from '../get-service.service';

  selector: 'app-campaign',
  templateUrl: './campaign.component.html',
  styleUrls: ['./campaign.component.css']
export class CampaignComponent implements OnInit {
    private campaignService: GetServiceService,
  ) { }

  ngOnInit(): void {
    this.campaigns = this.campaignService.getCampaign();



import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

  providedIn: 'root'
export class GetServiceService {

    private http: HttpClient
  ) { }

    return this.http.get('')

So my expectation is that this code would give out the list of data in my API (ignore the first ). What actually happen is that the table only show the first , which means the data is not showing up on the table.

The error in the console is

ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
    at NgForOf.ngDoCheck (common.js:3184)
    at callHook (core.js:2536)
    at callHooks (core.js:2495)
    at executeCheckHooks (core.js:2427)
    at refreshView (core.js:9474)
    at refreshComponent (core.js:10636)
    at refreshChildComponents (core.js:9261)
    at refreshView (core.js:9515)
    at refreshEmbeddedViews (core.js:10590)
    at refreshView (core.js:9489)

The data in api from postman get is

    "success": true,
    "message": "success",
    "data": [
            "id": 1,
            "name": "buattoko"
            "id": 2,
            "name": "omnipos"
            "id": 3,
            "name": "pluscampaign"

what do I need to do to get the data to the table?


Add pipe and map rxjs operator to transform the result as


import { map } from 'rxjs/operators';

getCampaign() {
  return this.http.get('')
    .pipe(map((response: any) =>;

Sample Solution on StackBlitz

Answered By – Yong Shun

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published