亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從 json 文件填充國家到 angular2-multiselect

從 json 文件填充國家到 angular2-multiselect

aluckdog 2022-12-09 16:48:17
我想嘗試從 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); } }此顯示數據:在控制臺日志中未定義。請幫我解決
查看完整描述

1 回答

?
九州編程

TA貢獻1785條經驗 獲得超4個贊

使用以下代碼獲取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')

 )

}


查看完整回答
反對 回復 2022-12-09
  • 1 回答
  • 0 關注
  • 101 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號