将国家/地区从 json 文件填充到 angular2-multiselect

Populate countries from json file to angular2-multiselect

我想尝试从 json 文件 url: https://raw.githubusercontent.com/sagarshirbhate/Country-State-City-Database/master/Contries.json 加载国家到 angular2-multiselect。下面是我的代码

getCountries(){
this.country.allCountries().
subscribe(
    data2 => {
      this.countryInfo = data2.Countries.CountryName;
      console.log('Data:', this.countryInfo);
    },
    err => console.log(err),
    () => console.log('complete')
 )
}

所以 getcountry 函数从我用 url 创建的服务中获取数据,这里是服务

  export class CountriesService {
  url: string = "https://raw.githubusercontent.com/sagarshirbhate/Country-State-City- 
  Database/master/Contries.json";

  constructor(private http: HttpClient) { }

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

此显示数据:控制台日志未定义。请帮我解决一下

使用下面的代码获取CountryName

getCountries(){
 this.countryInfo = [];
this.country.allCountries().
subscribe(
    data2 => {
     
        data2.Countries.forEach(element => {
          this.countryInfo.push(element.CountryName);
        });
      console.log('Data:', this.countryInfo);
    },
    err => console.log(err),
    () => console.log('complete')
 )
}