Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ionic-解析JSON内容并在模式控制器中显示它_Javascript_Json_Parsing_Ionic Framework_Rxjs - Fatal编程技术网

Javascript Ionic-解析JSON内容并在模式控制器中显示它

Javascript Ionic-解析JSON内容并在模式控制器中显示它,javascript,json,parsing,ionic-framework,rxjs,Javascript,Json,Parsing,Ionic Framework,Rxjs,我使用的是Ionic,我希望在模式组件中显示JSON解析(URL)的内容。我设法获取JSON查询的内容,但当我尝试将其插入模式时,它返回未定义的内容 以下是片段: async openModal(){ this.http.get(URL.subscribe)( (数据)=>{ var URLparsed=data['features'][0]['properties']['nom_dep']; console.log(URLparsed);//返回内容,没关系 this.URLparsed2=U

我使用的是Ionic,我希望在模式组件中显示JSON解析(URL)的内容。我设法获取JSON查询的内容,但当我尝试将其插入模式时,它返回未定义的内容

以下是片段:

async openModal(){
this.http.get(URL.subscribe)(
(数据)=>{
var URLparsed=data['features'][0]['properties']['nom_dep'];
console.log(URLparsed);//返回内容,没关系
this.URLparsed2=URLparsed;
},
(错误)=>{
console.log(错误);
},
);
console.log('verif:'+this.urlpassed2);//返回未定义的
const modal2=等待this.modalCtrl.create({
组件:Modal2页,
cssClass:“我的自定义类”,
组件和支柱:{
URL:this.URLparsed2,
},
});
return wait modal2.present();
}
我必须走这一步。你有什么想法吗?
非常感谢您的帮助。

谢谢

HTTP.get是异步的

console.log(URLparsed);//返回内容,没关系
console.log(“verif:+this.urlpassed2”)之后调用;//返回未定义的

您可以将
get()
方法返回的RxJs
Observable
转换为
Promise
,然后等待该Promise得到解决

async openModal(){
让data=wait this.http.get(URL.toPromise();
var URLparsed=(数据['features'][0]['properties']['nom_dep']);
console.log(URLparsed);//返回内容,没关系
this.URLparsed2=URLparsed;
log(“verif:+this.urlpassed2”);
const modal2=等待this.modalCtrl.create({
组件:Modal2页,
cssClass:“我的自定义类”,
组件和支柱:{
“URL”:this.URLparsed2,
}
});
return wait modal2.present();
}

此代码是一个示例,未经测试。

请正确缩进代码以便于阅读。我测试了您的代码,这正是我需要的!非常感谢@Marco!!