Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.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
将Api响应存储在变量内部_Api_Ionic Framework_Ionic3 - Fatal编程技术网

将Api响应存储在变量内部

将Api响应存储在变量内部,api,ionic-framework,ionic3,Api,Ionic Framework,Ionic3,我想存储call-in变量的respond,然后在代码中使用它,但是如果我查看控制台,就会发现它没有定义 getdata(){ return this.http.get<any>('url', { headers: header }) } this.testProvider.getdata().subscribe(data => {this.films=data.name console.log(this.f

我想存储call-in变量的respond,然后在代码中使用它,但是如果我查看控制台,就会发现它没有定义

      getdata(){

          return this.http.get<any>('url', { headers: header })    
  }

    this.testProvider.getdata().subscribe(data => 
      {this.films=data.name
console.log(this.films);
    })
getdata(){
返回此.http.get('url',{headers:header})
}
this.testProvider.getdata().subscribe(数据=>
{this.films=data.name
console.log(this.films);
})

您应该这样做
this.films=data.content.name


编辑:
this.films=data.content[index].name

我们需要更多信息。此端点的后端看起来如何?数据是否也未定义?否如果我删除.name{content:Array(2),pageable:{…},totalPages:1,totalElements:2,last:true,…}content:Array(2)0:{id:1,name:“test1,name_at:null,}1:{id:2,name:“test”,name_aa“test”}长度:2__proto__:它也给了我未定义的另一件事我已经将电影设置为电影:可观察的;这可能是问题吗?如果我这样做,我可以得到它的名称,但是有很多步骤让x:any x=this.films console.log(x.content);for(让y of x.content){console.log(y.name)}问题的出现是因为电影:Observable我已经将其更改为films:any,现在它工作正常。我忘了提到您应该执行data.content[index]。name,因为我看到它是您在上面的注释中放置的内容的数组。如果您有2个元素,则索引将为0或1