【问题标题】:Contentful getAsset retunrs undefined内容丰富的 getAsset 返回 undefined
【发布时间】:2020-07-24 06:37:21
【问题描述】:

我正在尝试从 Contentful 获取资产、图像到我的 Angular 应用程序中。在网络日志中我得到图像时,它在我的 console.log 中一直显示undefined。知道为什么吗?

这是组件中的函数:

    this.contentfulService.getContactImage()
      .then(asset => this.pageImage)
      .then(asset => console.log("Recieved Gallery Image", this.pageImage));

这里是服务:

  //get Page Image
  getContactImage() {
    return this.cdaClient.getAsset('<asset ID>')
      .then(asset => asset.fields.file.url);
  }

【问题讨论】:

    标签: javascript angular typescript contentful


    【解决方案1】:

    您不认为,您返回的是您从未分配过的this.pageImage..

    this.contentfulService.getContactImage()
          .then(asset => **this.pageImage**)
          .then(asset => console.log("Recieved Gallery Image", this.pageImage));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-13
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 2020-11-14
      • 1970-01-01
      • 2022-08-07
      • 1970-01-01
      相关资源
      最近更新 更多