Cannot read property 'country_name' of undefined


#1

home.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Http, Response } from '@angular/http';
import 'rxjs/add/operator/map';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  private apiurl = 'http://34.215.46.34/api.php?q=';
  data: any = {};

  constructor(public navCtrl: NavController, private http: Http) {
    console.log("Countries api");
    this.getcountry();
    this.getdata();
  }

  getdata(){
    return this.http.get(this.apiurl)
    .map((res: Response) => res.json())
  }
  getcountry(){
    this.getdata().subscribe(data =>{
      console.log(data);
      this.data = data
    })

  }

}

home.html

<ion-header>
  <ion-navbar>
    <ion-title>
      Ionic Blank
    </ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
    <ion-list>
  <ion-item *ngFor="let countries of country">
    </ion-item></ion-list>
    <h2>{{countries.country_name}}</h2>
  </ion-content>

can anyone help me with this


<ion-select> not showing list items on android in ionic
#2

where is your <ion-item *ngFor=“let countries of country”> variable ?
use data variable instead of country


#3

I am getting this but the output is not seen in the mobile screen

<ion-content padding>
    <ion-list>
  <ion-item *ngFor="let data of country">
    </ion-item></ion-list>
    <h2>{{data.country_name}}</h2>
  </ion-content>

output


#4

can you show me your your json output ?


#5

Shouldn’t your h2 be inside the ion-item?

Also, you never define not assign country inside your template, instead you define and assign data, so I believe you want let countries of data.


#6
<ion-content padding>
    <ion-list>
  <ion-item *ngFor="let countries of data">
      <h2>{{data.country_name}}</h2>
    </ion-item></ion-list>
    
  </ion-content>

error

ERROR Error: Uncaught (in promise): Error: Cannot find a differ supporting object ‘[object Object]’ of type ‘object’. NgFor only supports binding to Iterables such as Arrays.
Error: Cannot find a differ supporting object ‘[object Object]’ of type ‘object’. NgFor only supports binding to Iterables such as Arrays.
at NgForOf.ngOnChanges (common.es5.js:1681)


#7

it should be

{{countries.country_name}}


#8
<ion-content padding>
    <ion-list>
  <ion-item *ngFor="let countries of data">
      <h2>{{countries.country_name}}</h2>
    </ion-item></ion-list>
    
  </ion-content>

error:

ERROR Error: Uncaught (in promise): Error: Cannot find a differ supporting object ‘[object Object]’ of type ‘object’. NgFor only supports binding to Iterables such as Arrays.
Error: Cannot find a differ supporting object ‘[object Object]’ of type ‘object’. NgFor only supports binding to Iterables such as Arrays.


#9

what is your data structure


#10
[
  {
    "0": "1",
    "1": "AF",
    "2": "Afghanistan",
    "id": "1",
    "country_code": "AF",
    "country_name": "Afghanistan"
  },
  {
    "0": "2",
    "1": "AL",
    "2": "Albania",
    "id": "2",
    "country_code": "AL",
    "country_name": "Albania"
  },
  {
    "0": "3",
    "1": "DZ",
    "2": "Algeria",
    "id": "3",
    "country_code": "DZ",
    "country_name": "Algeria"
  },
  {
    "0": "4",
    "1": "DS",
    "2": "American Samoa",
    "id": "4",
    "country_code": "DS",
    "country_name": "American Samoa"
  },
  {
    "0": "5",
    "1": "AD",
    "2": "Andorra",
    "id": "5",
    "country_code": "AD",
    "country_name": "Andorra"
  },
  {
    "0": "6",
    "1": "AO",
    "2": "Angola",
    "id": "6",
    "country_code": "AO",
    "country_name": "Angola"
  },
  {
    "0": "7",
    "1": "AI",
    "2": "Anguilla",
    "id": "7",
    "country_code": "AI",
    "country_name": "Anguilla"
  },
  {
    "0": "8",
    "1": "AQ",
    "2": "Antarctica",
    "id": "8",
    "country_code": "AQ",
    "country_name": "Antarctica"
  },
  {
    "0": "9",
    "1": "AG",
    "2": "Antigua and Barbuda",
    "id": "9",
    "country_code": "AG",
    "country_name": "Antigua and Barbuda"
  },
  {
    "0": "10",
    "1": "AR",
    "2": "Argentina",
    "id": "10",
    "country_code": "AR",
    "country_name": "Argentina"
  },
  {
    "0": "11",
    "1": "AM",
    "2": "Armenia",
    "id": "11",
    "country_code": "AM",
    "country_name": "Armenia"
  },
  {
    "0": "12",
    "1": "AW",
    "2": "Aruba",
    "id": "12",
    "country_code": "AW",
    "country_name": "Aruba"
  },
  {
    "0": "13",
    "1": "AU",
    "2": "Australia",
    "id": "13",
    "country_code": "AU",
    "country_name": "Australia"
  },
  {
    "0": "14",
    "1": "AT",
    "2": "Austria",
    "id": "14",
    "country_code": "AT",
    "country_name": "Austria"
  },
  {
    "0": "15",
    "1": "AZ",
    "2": "Azerbaijan",
    "id": "15",
    "country_code": "AZ",
    "country_name": "Azerbaijan"
  },
  {
    "0": "16",
    "1": "BS",
    "2": "Bahamas",
    "id": "16",
    "country_code": "BS",
    "country_name": "Bahamas"
  },
  {
    "0": "17",
    "1": "BH",
    "2": "Bahrain",
    "id": "17",
    "country_code": "BH",
    "country_name": "Bahrain"
  },
  {
    "0": "18",
    "1": "BD",
    "2": "Bangladesh",
    "id": "18",
    "country_code": "BD",
    "country_name": "Bangladesh"
  },
  {
    "0": "19",
    "1": "BB",
    "2": "Barbados",
    "id": "19",
    "country_code": "BB",
    "country_name": "Barbados"
  },
  {
    "0": "20",
    "1": "BY",
    "2": "Belarus",
    "id": "20",
    "country_code": "BY",
    "country_name": "Belarus"
  },
  {
    "0": "21",
    "1": "BE",
    "2": "Belgium",
    "id": "21",
    "country_code": "BE",
    "country_name": "Belgium"
  },
  {
    "0": "22",
    "1": "BZ",
    "2": "Belize",
    "id": "22",
    "country_code": "BZ",
    "country_name": "Belize"
  },
  {
    "0": "23",
    "1": "BJ",
    "2": "Benin",
    "id": "23",
    "country_code": "BJ",
    "country_name": "Benin"
  },
  {
    "0": "24",
    "1": "BM",
    "2": "Bermuda",
    "id": "24",
    "country_code": "BM",
    "country_name": "Bermuda"
  },
  {
    "0": "25",
    "1": "BT",
    "2": "Bhutan",
    "id": "25",
    "country_code": "BT",
    "country_name": "Bhutan"
  },
  {
    "0": "26",
    "1": "BO",
    "2": "Bolivia",
    "id": "26",
    "country_code": "BO",
    "country_name": "Bolivia"
  },
  {
    "0": "27",
    "1": "BA",
    "2": "Bosnia and Herzegovina",
    "id": "27",
    "country_code": "BA",
    "country_name": "Bosnia and Herzegovina"
  },
  {
    "0": "28",
    "1": "BW",
    "2": "Botswana",
    "id": "28",
    "country_code": "BW",
    "country_name": "Botswana"
  },
  {
    "0": "29",
    "1": "BV",
    "2": "Bouvet Island",
    "id": "29",
    "country_code": "BV",
    "country_name": "Bouvet Island"
  },
  {
    "0": "30",
    "1": "BR",
    "2": "Brazil",
    "id": "30",
    "country_code": "BR",
    "country_name": "Brazil"
  },
  {
    "0": "31",
    "1": "IO",
    "2": "British Indian Ocean Territory",
    "id": "31",
    "country_code": "IO",
    "country_name": "British Indian Ocean Territory"
  },
  {
    "0": "32",
    "1": "BN",
    "2": "Brunei Darussalam",
    "id": "32",
    "country_code": "BN",
    "country_name": "Brunei Darussalam"
  },
  {
    "0": "33",
    "1": "BG",
    "2": "Bulgaria",
    "id": "33",
    "country_code": "BG",
    "country_name": "Bulgaria"
  },
  {
    "0": "34",
    "1": "BF",
    "2": "Burkina Faso",
    "id": "34",
    "country_code": "BF",
    "country_name": "Burkina Faso"
  },
  {
    "0": "35",
    "1": "BI",
    "2": "Burundi",
    "id": "35",
    "country_code": "BI",
    "country_name": "Burundi"
  },
  {
    "0": "36",
    "1": "KH",
    "2": "Cambodia",
    "id": "36",
    "country_code": "KH",
    "country_name": "Cambodia"
  },
  {
    "0": "37",
    "1": "CM",
    "2": "Cameroon",
    "id": "37",
    "country_code": "CM",
    "country_name": "Cameroon"
  },
  {
    "0": "38",
    "1": "CA",
    "2": "Canada",
    "id": "38",
    "country_code": "CA",
    "country_name": "Canada"
  },
  {
    "0": "39",
    "1": "CV",
    "2": "Cape Verde",
    "id": "39",
    "country_code": "CV",
    "country_name": "Cape Verde"
  },
  {
    "0": "40",
    "1": "KY",
    "2": "Cayman Islands",
    "id": "40",
    "country_code": "KY",
    "country_name": "Cayman Islands"
  },
  {
    "0": "41",
    "1": "CF",
    "2": "Central African Republic",
    "id": "41",
    "country_code": "CF",
    "country_name": "Central African Republic"
  },
  {
    "0": "42",
    "1": "TD",
    "2": "Chad",
    "id": "42",
    "country_code": "TD",
    "country_name": "Chad"
  },
  {
    "0": "43",
    "1": "CL",
    "2": "Chile",
    "id": "43",
    "country_code": "CL",
    "country_name": "Chile"
  },
  {
    "0": "44",
    "1": "CN",
    "2": "China",
    "id": "44",
    "country_code": "CN",
    "country_name": "China"
  },
  {
    "0": "45",
    "1": "CX",
    "2": "Christmas Island",
    "id": "45",
    "country_code": "CX",
    "country_name": "Christmas Island"
  },
  {
    "0": "46",
    "1": "CC",
    "2": "Cocos (Keeling) Islands",
    "id": "46",
    "country_code": "CC",
    "country_name": "Cocos (Keeling) Islands"
  },
  {
    "0": "47",
    "1": "CO",
    "2": "Colombia",
    "id": "47",
    "country_code": "CO",
    "country_name": "Colombia"
  },
  {
    "0": "48",
    "1": "KM",
    "2": "Comoros",
    "id": "48",
    "country_code": "KM",
    "country_name": "Comoros"
  },
  {
    "0": "49",
    "1": "CG",
    "2": "Congo",
    "id": "49",
    "country_code": "CG",
    "country_name": "Congo"
  },
  {
    "0": "50",
    "1": "CK",
    "2": "Cook Islands",
    "id": "50",
    "country_code": "CK",
    "country_name": "Cook Islands"
  },
  {
    "0": "51",
    "1": "CR",
    "2": "Costa Rica",
    "id": "51",
    "country_code": "CR",
    "country_name": "Costa Rica"
  },
  {
    "0": "52",
    "1": "HR",
    "2": "Croatia (Hrvatska)",
    "id": "52",
    "country_code": "HR",
    "country_name": "Croatia (Hrvatska)"
  },
  {
    "0": "53",
    "1": "CU",
    "2": "Cuba",
    "id": "53",
    "country_code": "CU",
    "country_name": "Cuba"
  },
  {
    "0": "54",
    "1": "CY",
    "2": "Cyprus",
    "id": "54",
    "country_code": "CY",
    "country_name": "Cyprus"
  },
  {
    "0": "55",
    "1": "CZ",
    "2": "Czech Republic",
    "id": "55",
    "country_code": "CZ",
    "country_name": "Czech Republic"
  },
  {
    "0": "56",
    "1": "DK",
    "2": "Denmark",
    "id": "56",
    "country_code": "DK",
    "country_name": "Denmark"
  },
  {
    "0": "57",
    "1": "DJ",
    "2": "Djibouti",
    "id": "57",
    "country_code": "DJ",
    "country_name": "Djibouti"
  },
  {
    "0": "58",
    "1": "DM",
    "2": "Dominica",
    "id": "58",
    "country_code": "DM",
    "country_name": "Dominica"
  },
  {
    "0": "59",
    "1": "DO",
    "2": "Dominican Republic",
    "id": "59",
    "country_code": "DO",
    "country_name": "Dominican Republic"
  },
  {
    "0": "60",
    "1": "TP",
    "2": "East Timor",
    "id": "60",
    "country_code": "TP",
    "country_name": "East Timor"
  },
  {
    "0": "61",
    "1": "EC",
    "2": "Ecuador",
    "id": "61",
    "country_code": "EC",
    "country_name": "Ecuador"
  },
  {
    "0": "62",
    "1": "EG",
    "2": "Egypt",
    "id": "62",
    "country_code": "EG",
    "country_name": "Egypt"
  },
  {
    "0": "63",
    "1": "SV",
    "2": "El Salvador",
    "id": "63",
    "country_code": "SV",
    "country_name": "El Salvador"
  },
  {
    "0": "64",
    "1": "GQ",
    "2": "Equatorial Guinea",
    "id": "64",
    "country_code": "GQ",
    "country_name": "Equatorial Guinea"
  },
  {
    "0": "65",
    "1": "ER",
    "2": "Eritrea",
    "id": "65",
    "country_code": "ER",
    "country_name": "Eritrea"
  },
  {
    "0": "66",
    "1": "EE",
    "2": "Estonia",
    "id": "66",
    "country_code": "EE",
    "country_name": "Estonia"
  },
  {
    "0": "67",
    "1": "ET",
    "2": "Ethiopia",
    "id": "67",
    "country_code": "ET",
    "country_name": "Ethiopia"
  },
  {
    "0": "68",
    "1": "FK",
    "2": "Falkland Islands (Malvinas)",
    "id": "68",
    "country_code": "FK",
    "country_name": "Falkland Islands (Malvinas)"
  },
  {
    "0": "69",
    "1": "FO",
    "2": "Faroe Islands",
    "id": "69",
    "country_code": "FO",
    "country_name": "Faroe Islands"
  },
  {
    "0": "70",
    "1": "FJ",
    "2": "Fiji",
    "id": "70",
    "country_code": "FJ",
    "country_name": "Fiji"
  },
  {
    "0": "71",
    "1": "FI",
    "2": "Finland",
    "id": "71",
    "country_code": "FI",
    "country_name": "Finland"
  },
  {
    "0": "72",
    "1": "FR",
    "2": "France",
    "id": "72",
    "country_code": "FR",
    "country_name": "France"
  },
  {
    "0": "73",
    "1": "FX",
    "2": "France, Metropolitan",
    "id": "73",
    "country_code": "FX",
    "country_name": "France, Metropolitan"
  },
  {
    "0": "74",
    "1": "GF",
    "2": "French Guiana",
    "id": "74",
    "country_code": "GF",
    "country_name": "French Guiana"
  },
  {
    "0": "75",
    "1": "PF",
    "2": "French Polynesia",
    "id": "75",
    "country_code": "PF",
    "country_name": "French Polynesia"
  },
  {
    "0": "76",
    "1": "TF",
    "2": "French Southern Territories",
    "id": "76",
    "country_code": "TF",
    "country_name": "French Southern Territories"
  },
  {
    "0": "77",
    "1": "GA",
    "2": "Gabon",
    "id": "77",
    "country_code": "GA",
    "country_name": "Gabon"
  },
  {
    "0": "78",
    "1": "GM",
    "2": "Gambia",
    "id": "78",
    "country_code": "GM",
    "country_name": "Gambia"
  },
  {
    "0": "79",
    "1": "GE",
    "2": "Georgia",
    "id": "79",
    "country_code": "GE",
    "country_name": "Georgia"
  },
  {
    "0": "80",
    "1": "DE",
    "2": "Germany",
    "id": "80",
    "country_code": "DE",
    "country_name": "Germany"
  },
  {
    "0": "81",
    "1": "GH",
    "2": "Ghana",
    "id": "81",
    "country_code": "GH",
    "country_name": "Ghana"
  },
  {
    "0": "82",
    "1": "GI",
    "2": "Gibraltar",
    "id": "82",
    "country_code": "GI",
    "country_name": "Gibraltar"
  },
  {
    "0": "83",
    "1": "GK",
    "2": "Guernsey",
    "id": "83",
    "country_code": "GK",
    "country_name": "Guernsey"
  },
  {
    "0": "84",
    "1": "GR",
    "2": "Greece",
    "id": "84",
    "country_code": "GR",
    "country_name": "Greece"
  },
  {
    "0": "85",
    "1": "GL",
    "2": "Greenland",
    "id": "85",
    "country_code": "GL",
    "country_name": "Greenland"
  },
  {
    "0": "86",
    "1": "GD",
    "2": "Grenada",
    "id": "86",
    "country_code": "GD",
    "country_name": "Grenada"
  },
  {
    "0": "87",
    "1": "GP",
    "2": "Guadeloupe",
    "id": "87",
    "country_code": "GP",
    "country_name": "Guadeloupe"
  },
  {
    "0": "88",
    "1": "GU",
    "2": "Guam",
    "id": "88",
    "country_code": "GU",
    "country_name": "Guam"
  },
  {
    "0": "89",
    "1": "GT",
    "2": "Guatemala",
    "id": "89",
    "country_code": "GT",
    "country_name": "Guatemala"
  },
  {
    "0": "90",
    "1": "GN",
    "2": "Guinea",
    "id": "90",
    "country_code": "GN",
    "country_name": "Guinea"
  },
  {
    "0": "91",
    "1": "GW",
    "2": "Guinea-Bissau",
    "id": "91",
    "country_code": "GW",
    "country_name": "Guinea-Bissau"
  },
  {
    "0": "92",
    "1": "GY",
    "2": "Guyana",
    "id": "92",
    "country_code": "GY",
    "country_name": "Guyana"
  },
  {
    "0": "93",
    "1": "HT",
    "2": "Haiti",
    "id": "93",
    "country_code": "HT",
    "country_name": "Haiti"
  },
  {
    "0": "94",
    "1": "HM",
    "2": "Heard and Mc Donald Islands",
    "id": "94",
    "country_code": "HM",
    "country_name": "Heard and Mc Donald Islands"
  },
  {
    "0": "95",
    "1": "HN",
    "2": "Honduras",
    "id": "95",
    "country_code": "HN",
    "country_name": "Honduras"
  },
  {
    "0": "96",
    "1": "HK",
    "2": "Hong Kong",
    "id": "96",
    "country_code": "HK",
    "country_name": "Hong Kong"
  },
  {
    "0": "97",
    "1": "HU",
    "2": "Hungary",
    "id": "97",
    "country_code": "HU",
    "country_name": "Hungary"
  },
  {
    "0": "98",
    "1": "IS",
    "2": "Iceland",
    "id": "98",
    "country_code": "IS",
    "country_name": "Iceland"
  },
  {
    "0": "99",
    "1": "IN",
    "2": "India",
    "id": "99",
    "country_code": "IN",
    "country_name": "India"
  },
  {
    "0": "100",
    "1": "IM",
    "2": "Isle of Man",
    "id": "100",
    "country_code": "IM",
    "country_name": "Isle of Man"
  },
  {
    "0": "101",
    "1": "ID",
    "2": "Indonesia",
    "id": "101",
    "country_code": "ID",
    "country_name": "Indonesia"
  },
  {
    "0": "102",
    "1": "IR",
    "2": "Iran (Islamic Republic of)",
    "id": "102",
    "country_code": "IR",
    "country_name": "Iran (Islamic Republic of)"
  },
  {
    "0": "103",
    "1": "IQ",
    "2": "Iraq",
    "id": "103",
    "country_code": "IQ",
    "country_name": "Iraq"
  },
  {
    "0": "104",
    "1": "IE",
    "2": "Ireland",
    "id": "104",
    "country_code": "IE",
    "country_name": "Ireland"
  },
  {
    "0": "105",
    "1": "IL",
    "2": "Israel",
    "id": "105",
    "country_code": "IL",
    "country_name": "Israel"
  },
  {
    "0": "106",
    "1": "IT",
    "2": "Italy",
    "id": "106",
    "country_code": "IT",
    "country_name": "Italy"
  },
  {
    "0": "107",
    "1": "CI",
    "2": "Ivory Coast",
    "id": "107",
    "country_code": "CI",
    "country_name": "Ivory Coast"
  },
  {
    "0": "108",
    "1": "JE",
    "2": "Jersey",
    "id": "108",
    "country_code": "JE",
    "country_name": "Jersey"
  },
  {
    "0": "109",
    "1": "JM",
    "2": "Jamaica",
    "id": "109",
    "country_code": "JM",
    "country_name": "Jamaica"
  },
  {
    "0": "110",
    "1": "JP",
    "2": "Japan",
    "id": "110",
    "country_code": "JP",
    "country_name": "Japan"
  },
  {
    "0": "111",
    "1": "JO",
    "2": "Jordan",
    "id": "111",
    "country_code": "JO",
    "country_name": "Jordan"
  },
  {
    "0": "112",
    "1": "KZ",
    "2": "Kazakhstan",
    "id": "112",
    "country_code": "KZ",
    "country_name": "Kazakhstan"
  },
  {
    "0": "113",
    "1": "KE",
    "2": "Kenya",
    "id": "113",
    "country_code": "KE",
    "country_name": "Kenya"
  },
  {
    "0": "114",
    "1": "KI",
    "2": "Kiribati",
    "id": "114",
    "country_code": "KI",
    "country_name": "Kiribati"
  },
  {
    "0": "115",
    "1": "KP",
    "2": "Korea, Democratic People's Republic of",
    "id": "115",
    "country_code": "KP",
    "country_name": "Korea, Democratic People's Republic of"
  },
  {
    "0": "116",
    "1": "KR",
    "2": "Korea, Republic of",
    "id": "116",
    "country_code": "KR",
    "country_name": "Korea, Republic of"
  },
  {
    "0": "117",
    "1": "XK",
    "2": "Kosovo",
    "id": "117",
    "country_code": "XK",
    "country_name": "Kosovo"
  },
  {
    "0": "118",
    "1": "KW",
    "2": "Kuwait",
    "id": "118",
    "country_code": "KW",
    "country_name": "Kuwait"
  },
  {
    "0": "119",
    "1": "KG",
    "2": "Kyrgyzstan",
    "id": "119",
    "country_code": "KG",
    "country_name": "Kyrgyzstan"
  },
  {
    "0": "120",
    "1": "LA",
    "2": "Lao People's Democratic Republic",
    "id": "120",
    "country_code": "LA",
    "country_name": "Lao People's Democratic Republic"
  },
  {
    "0": "121",
    "1": "LV",
    "2": "Latvia",
    "id": "121",
    "country_code": "LV",
    "country_name": "Latvia"
  },
  {
    "0": "122",
    "1": "LB",
    "2": "Lebanon",
    "id": "122",
    "country_code": "LB",
    "country_name": "Lebanon"
  },
  {
    "0": "123",
    "1": "LS",
    "2": "Lesotho",
    "id": "123",
    "country_code": "LS",
    "country_name": "Lesotho"
  },
  {
    "0": "124",
    "1": "LR",
    "2": "Liberia",
    "id": "124",
    "country_code": "LR",
    "country_name": "Liberia"
  },
  {
    "0": "125",
    "1": "LY",
    "2": "Libyan Arab Jamahiriya",
    "id": "125",
    "country_code": "LY",
    "country_name": "Libyan Arab Jamahiriya"
  },
  {
    "0": "126",
    "1": "LI",
    "2": "Liechtenstein",
    "id": "126",
    "country_code": "LI",
    "country_name": "Liechtenstein"
  },
  {
    "0": "127",
    "1": "LT",
    "2": "Lithuania",
    "id": "127",
    "country_code": "LT",
    "country_name": "Lithuania"
  },
  {
    "0": "128",
    "1": "LU",
    "2": "Luxembourg",
    "id": "128",
    "country_code": "LU",
    "country_name": "Luxembourg"
  },
  {
    "0": "129",
    "1": "MO",
    "2": "Macau",
    "id": "129",
    "country_code": "MO",
    "country_name": "Macau"
  },
  {
    "0": "130",
    "1": "MK",
    "2": "Macedonia",
    "id": "130",
    "country_code": "MK",
    "country_name": "Macedonia"
  },
  {
    "0": "131",
    "1": "MG",
    "2": "Madagascar",
    "id": "131",
    "country_code": "MG",
    "country_name": "Madagascar"
  },
  {
    "0": "132",
    "1": "MW",
    "2": "Malawi",
    "id": "132",
    "country_code": "MW",
    "country_name": "Malawi"
  },
  {
    "0": "133",
    "1": "MY",
    "2": "Malaysia",
    "id": "133",
    "country_code": "MY",
    "country_name": "Malaysia"
  },
  {
    "0": "134",
    "1": "MV",
    "2": "Maldives",
    "id": "134",
    "country_code": "MV",
    "country_name": "Maldives"
  },
  {
    "0": "135",
    "1": "ML",
    "2": "Mali",
    "id": "135",
    "country_code": "ML",
    "country_name": "Mali"
  },
  {
    "0": "136",
    "1": "MT",
    "2": "Malta",
    "id": "136",
    "country_code": "MT",
    "country_name": "Malta"
  },
  {
    "0": "137",
    "1": "MH",
    "2": "Marshall Islands",
    "id": "137",
    "country_code": "MH",
    "country_name": "Marshall Islands"
  },
  {
    "0": "138",
    "1": "MQ",
    "2": "Martinique",
    "id": "138",
    "country_code": "MQ",
    "country_name": "Martinique"
  },
  {
    "0": "139",
    "1": "MR",
    "2": "Mauritania",
    "id": "139",
    "country_code": "MR",
    "country_name": "Mauritania"
  },
  {
    "0": "140",
    "1": "MU",
    "2": "Mauritius",
    "id": "140",
    "country_code": "MU",
    "country_name": "Mauritius"
  },
  {
    "0": "141",
    "1": "TY",
    "2": "Mayotte",
    "id": "141",
    "country_code": "TY",
    "country_name": "Mayotte"
  },
  {
    "0": "142",
    "1": "MX",
    "2": "Mexico",
    "id": "142",
    "country_code": "MX",
    "country_name": "Mexico"
  },
  {
    "0": "143",
    "1": "FM",
    "2": "Micronesia, Federated States of",
    "id": "143",
    "country_code": "FM",
    "country_name": "Micronesia, Federated States of"
  },
  {
    "0": "144",
    "1": "MD",
    "2": "Moldova, Republic of",
    "id": "144",
    "country_code": "MD",
    "country_name": "Moldova, Republic of"
  },
  {
    "0": "145",
    "1": "MC",
    "2": "Monaco",
    "id": "145",
    "country_code": "MC",
    "country_name": "Monaco"
  },
  {
    "0": "146",
    "1": "MN",
    "2": "Mongolia",
    "id": "146",
    "country_code": "MN",
    "country_name": "Mongolia"
  },
  {
    "0": "147",
    "1": "ME",
    "2": "Montenegro",
    "id": "147",
    "country_code": "ME",
    "country_name": "Montenegro"
  },
  {
    "0": "148",
    "1": "MS",
    "2": "Montserrat",
    "id": "148",
    "country_code": "MS",
    "country_name": "Montserrat"
  },
  {
    "0": "149",
    "1": "MA",
    "2": "Morocco",
    "id": "149",
    "country_code": "MA",
    "country_name": "Morocco"
  },
  {
    "0": "150",
    "1": "MZ",
    "2": "Mozambique",
    "id": "150",
    "country_code": "MZ",
    "country_name": "Mozambique"
  },
  {
    "0": "151",
    "1": "MM",
    "2": "Myanmar",
    "id": "151",
    "country_code": "MM",
    "country_name": "Myanmar"
  },
  {
    "0": "152",
    "1": "NA",
    "2": "Namibia",
    "id": "152",
    "country_code": "NA",
    "country_name": "Namibia"
  },
  {
    "0": "153",
    "1": "NR",
    "2": "Nauru",
    "id": "153",
    "country_code": "NR",
    "country_name": "Nauru"
  },
  {
    "0": "154",
    "1": "NP",
    "2": "Nepal",
    "id": "154",
    "country_code": "NP",
    "country_name": "Nepal"
  },
  {
    "0": "155",
    "1": "NL",
    "2": "Netherlands",
    "id": "155",
    "country_code": "NL",
    "country_name": "Netherlands"
  },
  {
    "0": "156",
    "1": "AN",
    "2": "Netherlands Antilles",
    "id": "156",
    "country_code": "AN",
    "country_name": "Netherlands Antilles"
  },
  {
    "0": "157",
    "1": "NC",
    "2": "New Caledonia",
    "id": "157",
    "country_code": "NC",
    "country_name": "New Caledonia"
  },
  {
    "0": "158",
    "1": "NZ",
    "2": "New Zealand",
    "id": "158",
    "country_code": "NZ",
    "country_name": "New Zealand"
  },
  {
    "0": "159",
    "1": "NI",
    "2": "Nicaragua",
    "id": "159",
    "country_code": "NI",
    "country_name": "Nicaragua"
  },
  {
    "0": "160",
    "1": "NE",
    "2": "Niger",
    "id": "160",
    "country_code": "NE",
    "country_name": "Niger"
  },
  {
    "0": "161",
    "1": "NG",
    "2": "Nigeria",
    "id": "161",
    "country_code": "NG",
    "country_name": "Nigeria"
  },
  {
    "0": "162",
    "1": "NU",
    "2": "Niue",
    "id": "162",
    "country_code": "NU",
    "country_name": "Niue"
  },
  {
    "0": "163",
    "1": "NF",
    "2": "Norfolk Island",
    "id": "163",
    "country_code": "NF",
    "country_name": "Norfolk Island"
  },
  {
    "0": "164",
    "1": "MP",
    "2": "Northern Mariana Islands",
    "id": "164",
    "country_code": "MP",
    "country_name": "Northern Mariana Islands"
  },
  {
    "0": "165",
    "1": "NO",
    "2": "Norway",
    "id": "165",
    "country_code": "NO",
    "country_name": "Norway"
  },
  {
    "0": "166",
    "1": "OM",
    "2": "Oman",
    "id": "166",
    "country_code": "OM",
    "country_name": "Oman"
  },
  {
    "0": "167",
    "1": "PK",
    "2": "Pakistan",
    "id": "167",
    "country_code": "PK",
    "country_name": "Pakistan"
  },
  {
    "0": "168",
    "1": "PW",
    "2": "Palau",
    "id": "168",
    "country_code": "PW",
    "country_name": "Palau"
  },
  {
    "0": "169",
    "1": "PS",
    "2": "Palestine",
    "id": "169",
    "country_code": "PS",
    "country_name": "Palestine"
  },
  {
    "0": "170",
    "1": "PA",
    "2": "Panama",
    "id": "170",
    "country_code": "PA",
    "country_name": "Panama"
  },
  {
    "0": "171",
    "1": "PG",
    "2": "Papua New Guinea",
    "id": "171",
    "country_code": "PG",
    "country_name": "Papua New Guinea"
  },
  {
    "0": "172",
    "1": "PY",
    "2": "Paraguay",
    "id": "172",
    "country_code": "PY",
    "country_name": "Paraguay"
  },
  {
    "0": "173",
    "1": "PE",
    "2": "Peru",
    "id": "173",
    "country_code": "PE",
    "country_name": "Peru"
  },
  {
    "0": "174",
    "1": "PH",
    "2": "Philippines",
    "id": "174",
    "country_code": "PH",
    "country_name": "Philippines"
  },
  {
    "0": "175",
    "1": "PN",
    "2": "Pitcairn",
    "id": "175",
    "country_code": "PN",
    "country_name": "Pitcairn"
  },
  {
    "0": "176",
    "1": "PL",
    "2": "Poland",
    "id": "176",
    "country_code": "PL",
    "country_name": "Poland"
  },
  {
    "0": "177",
    "1": "PT",
    "2": "Portugal",
    "id": "177",
    "country_code": "PT",
    "country_name": "Portugal"
  },
  {
    "0": "178",
    "1": "PR",
    "2": "Puerto Rico",
    "id": "178",
    "country_code": "PR",
    "country_name": "Puerto Rico"
  },
  {
    "0": "179",
    "1": "QA",
    "2": "Qatar",
    "id": "179",
    "country_code": "QA",
    "country_name": "Qatar"
  },
  {
    "0": "180",
    "1": "RE",
    "2": "Reunion",
    "id": "180",
    "country_code": "RE",
    "country_name": "Reunion"
  },
  {
    "0": "181",
    "1": "RO",
    "2": "Romania",
    "id": "181",
    "country_code": "RO",
    "country_name": "Romania"
  },
  {
    "0": "182",
    "1": "RU",
    "2": "Russian Federation",
    "id": "182",
    "country_code": "RU",
    "country_name": "Russian Federation"
  },
  {
    "0": "183",
    "1": "RW",
    "2": "Rwanda",
    "id": "183",
    "country_code": "RW",
    "country_name": "Rwanda"
  },
  {
    "0": "184",
    "1": "KN",
    "2": "Saint Kitts and Nevis",
    "id": "184",
    "country_code": "KN",
    "country_name": "Saint Kitts and Nevis"
  },
  {
    "0": "185",
    "1": "LC",
    "2": "Saint Lucia",
    "id": "185",
    "country_code": "LC",
    "country_name": "Saint Lucia"
  },
  {
    "0": "186",
    "1": "VC",
    "2": "Saint Vincent and the Grenadines",
    "id": "186",
    "country_code": "VC",
    "country_name": "Saint Vincent and the Grenadines"
  },
  {
    "0": "187",
    "1": "WS",
    "2": "Samoa",
    "id": "187",
    "country_code": "WS",
    "country_name": "Samoa"
  },
  {
    "0": "188",
    "1": "SM",
    "2": "San Marino",
    "id": "188",
    "country_code": "SM",
    "country_name": "San Marino"
  },
  {
    "0": "189",
    "1": "ST",
    "2": "Sao Tome and Principe",
    "id": "189",
    "country_code": "ST",
    "country_name": "Sao Tome and Principe"
  },
  {
    "0": "190",
    "1": "SA",
    "2": "Saudi Arabia",
    "id": "190",
    "country_code": "SA",
    "country_name": "Saudi Arabia"
  },
  {
    "0": "191",
    "1": "SN",
    "2": "Senegal",
    "id": "191",
    "country_code": "SN",
    "country_name": "Senegal"
  },
  {
    "0": "192",
    "1": "RS",
    "2": "Serbia",
    "id": "192",
    "country_code": "RS",
    "country_name": "Serbia"
  },
  {
    "0": "193",
    "1": "SC",
    "2": "Seychelles",
    "id": "193",
    "country_code": "SC",
    "country_name": "Seychelles"
  },
  {
    "0": "194",
    "1": "SL",
    "2": "Sierra Leone",
    "id": "194",
    "country_code": "SL",
    "country_name": "Sierra Leone"
  },
  {
    "0": "195",
    "1": "SG",
    "2": "Singapore",
    "id": "195",
    "country_code": "SG",
    "country_name": "Singapore"
  },
  {
    "0": "196",
    "1": "SK",
    "2": "Slovakia",
    "id": "196",
    "country_code": "SK",
    "country_name": "Slovakia"
  },
  {
    "0": "197",
    "1": "SI",
    "2": "Slovenia",
    "id": "197",
    "country_code": "SI",
    "country_name": "Slovenia"
  },
  {
    "0": "198",
    "1": "SB",
    "2": "Solomon Islands",
    "id": "198",
    "country_code": "SB",
    "country_name": "Solomon Islands"
  },
  {
    "0": "199",
    "1": "SO",
    "2": "Somalia",
    "id": "199",
    "country_code": "SO",
    "country_name": "Somalia"
  },
  {
    "0": "200",
    "1": "ZA",
    "2": "South Africa",
    "id": "200",
    "country_code": "ZA",
    "country_name": "South Africa"
  },
  {
    "0": "201",
    "1": "GS",
    "2": "South Georgia South Sandwich Islands",
    "id": "201",
    "country_code": "GS",
    "country_name": "South Georgia South Sandwich Islands"
  },
  {
    "0": "202",
    "1": "ES",
    "2": "Spain",
    "id": "202",
    "country_code": "ES",
    "country_name": "Spain"
  },
  {
    "0": "203",
    "1": "LK",
    "2": "Sri Lanka",
    "id": "203",
    "country_code": "LK",
    "country_name": "Sri Lanka"
  },
  {
    "0": "204",
    "1": "SH",
    "2": "St. Helena",
    "id": "204",
    "country_code": "SH",
    "country_name": "St. Helena"
  },
  {
    "0": "205",
    "1": "PM",
    "2": "St. Pierre and Miquelon",
    "id": "205",
    "country_code": "PM",
    "country_name": "St. Pierre and Miquelon"
  },
  {
    "0": "206",
    "1": "SD",
    "2": "Sudan",
    "id": "206",
    "country_code": "SD",
    "country_name": "Sudan"
  },
  {
    "0": "207",
    "1": "SR",
    "2": "Suriname",
    "id": "207",
    "country_code": "SR",
    "country_name": "Suriname"
  },
  {
    "0": "208",
    "1": "SJ",
    "2": "Svalbard and Jan Mayen Islands",
    "id": "208",
    "country_code": "SJ",
    "country_name": "Svalbard and Jan Mayen Islands"
  },
  {
    "0": "209",
    "1": "SZ",
    "2": "Swaziland",
    "id": "209",
    "country_code": "SZ",
    "country_name": "Swaziland"
  },
  {
    "0": "210",
    "1": "SE",
    "2": "Sweden",
    "id": "210",
    "country_code": "SE",
    "country_name": "Sweden"
  },
  {
    "0": "211",
    "1": "CH",
    "2": "Switzerland",
    "id": "211",
    "country_code": "CH",
    "country_name": "Switzerland"
  },
  {
    "0": "212",
    "1": "SY",
    "2": "Syrian Arab Republic",
    "id": "212",
    "country_code": "SY",
    "country_name": "Syrian Arab Republic"
  },
  {
    "0": "213",
    "1": "TW",
    "2": "Taiwan",
    "id": "213",
    "country_code": "TW",
    "country_name": "Taiwan"
  },
  {
    "0": "214",
    "1": "TJ",
    "2": "Tajikistan",
    "id": "214",
    "country_code": "TJ",
    "country_name": "Tajikistan"
  },
  {
    "0": "215",
    "1": "TZ",
    "2": "Tanzania, United Republic of",
    "id": "215",
    "country_code": "TZ",
    "country_name": "Tanzania, United Republic of"
  },
  {
    "0": "216",
    "1": "TH",
    "2": "Thailand",
    "id": "216",
    "country_code": "TH",
    "country_name": "Thailand"
  },
  {
    "0": "217",
    "1": "TG",
    "2": "Togo",
    "id": "217",
    "country_code": "TG",
    "country_name": "Togo"
  },
  {
    "0": "218",
    "1": "TK",
    "2": "Tokelau",
    "id": "218",
    "country_code": "TK",
    "country_name": "Tokelau"
  },
  {
    "0": "219",
    "1": "TO",
    "2": "Tonga",
    "id": "219",
    "country_code": "TO",
    "country_name": "Tonga"
  },
  {
    "0": "220",
    "1": "TT",
    "2": "Trinidad and Tobago",
    "id": "220",
    "country_code": "TT",
    "country_name": "Trinidad and Tobago"
  },
  {
    "0": "221",
    "1": "TN",
    "2": "Tunisia",
    "id": "221",
    "country_code": "TN",
    "country_name": "Tunisia"
  },
  {
    "0": "222",
    "1": "TR",
    "2": "Turkey",
    "id": "222",
    "country_code": "TR",
    "country_name": "Turkey"
  },
  {
    "0": "223",
    "1": "TM",
    "2": "Turkmenistan",
    "id": "223",
    "country_code": "TM",
    "country_name": "Turkmenistan"
  },
  {
    "0": "224",
    "1": "TC",
    "2": "Turks and Caicos Islands",
    "id": "224",
    "country_code": "TC",
    "country_name": "Turks and Caicos Islands"
  },
  {
    "0": "225",
    "1": "TV",
    "2": "Tuvalu",
    "id": "225",
    "country_code": "TV",
    "country_name": "Tuvalu"
  },
  {
    "0": "226",
    "1": "UG",
    "2": "Uganda",
    "id": "226",
    "country_code": "UG",
    "country_name": "Uganda"
  },
  {
    "0": "227",
    "1": "UA",
    "2": "Ukraine",
    "id": "227",
    "country_code": "UA",
    "country_name": "Ukraine"
  },
  {
    "0": "228",
    "1": "AE",
    "2": "United Arab Emirates",
    "id": "228",
    "country_code": "AE",
    "country_name": "United Arab Emirates"
  },
  {
    "0": "229",
    "1": "GB",
    "2": "United Kingdom",
    "id": "229",
    "country_code": "GB",
    "country_name": "United Kingdom"
  },
  {
    "0": "230",
    "1": "US",
    "2": "United States",
    "id": "230",
    "country_code": "US",
    "country_name": "United States"
  }
]

#11

just show one object of list. remove all this.

try this

 <ion-list  *ngFor="let countries of data">
 <ion-item >
      <h2>{{countries.country_name}}</h2>
    </ion-item></ion-list>

#12

ERROR Error: Uncaught (in promise): Error: Cannot find a differ supporting object ‘[object Object]’ of type ‘object’. NgFor only supports binding to Iterables such as Arrays.
Error: Cannot find a differ supporting object ‘[object Object]’ of type ‘object’. NgFor only supports binding to Iterables such as Arrays.


#13

you have to store your data into array variable then you can use ngFor
angular automatically convert json data into array but here it will not happen
so just declare one array variable in your ts file, asign data to that variable and use that variable in ngFor


#14

Here your code

varible in .ts file
country:any[]=[];

asign data
this.country=data;

your html file
<ion-list *ngFor=“let countries of country”>


#15


#16

try to print data of country in console
what is output ?


#17

wait can you show me your ts file code


#18
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Http, Response } from '@angular/http';
import 'rxjs/add/operator/map';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  private apiurl = 'http://34.215.46.34/api.php?q=';
  country:any[]=[];
  data: any = [];

  constructor(public navCtrl: NavController, private http: Http) {
    console.log("Countries api");
    this.getcountry();
    this.getdata();
    this.country=data;
  }

  getdata(){
    return this.http.get(this.apiurl)
    .map((res: Response) => res.json())
  }
  getcountry(){
    this.getdata().subscribe(data =>{
      console.log(data);
      this.data = data
    })

  }

}


#19

there is the issue => this.data = data
try direct assignment to country => this.country=data; into getcountry()
i think it still not work, right ?


#20

its the same again

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Http, Response } from '@angular/http';
import 'rxjs/add/operator/map';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  private apiurl = 'http://34.215.46.34/api.php?q=';
  country:any[]=[];
  data: any = [];

  constructor(public navCtrl: NavController, private http: Http) {
    console.log("Countries api");
    this.getcountry();
    this.getdata();
    
  }

  getdata(){
    return this.http.get(this.apiurl)
    .map((res: Response) => res.json())
  }
  getcountry(){
    this.getdata().subscribe(data =>{
      console.log(data);
      this.country=data;
    })

  }

}