我想尝试从 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);
}
}
此显示数据:在控制台日志中未定义。请帮我解决
九州编程
相关分类