javascript - 内容丰富的 getAsset 返回 undefined
问题描述
我正在尝试从 Contentful 获取资产、图像到我的 Angular 应用程序中。在网络日志中我得到图像时,它一直undefined
在我的 console.log 中显示。知道为什么吗?
这是组件中的功能:
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);
}
解决方案
你不认为,你正在返回this.pageImage
你从未分配过的东西。
this.contentfulService.getContactImage()
.then(asset => **this.pageImage**)
.then(asset => console.log("Recieved Gallery Image", this.pageImage));
推荐阅读
- python - 使用 python 针对大量概念字符串查找输入字符串中的所有概念
- algorithm - 多折线和多边形抽取的算法
- image - dcmtk 显示图像 Qt 示例
- python - python 3.6时间戳之间的短时间之和
- php - PHP shell_exec 不执行
- amazon-web-services - 如果我们在 CloudFormation 中有错误的条件和 Ref 会发生什么?
- haskell - Haskell:读取双精度文本文件并将包含它们的列表分配给列表变量
- vim - vim clang_complete 奇怪的完成错误
- bash - 如何逃避被单引号包围的回击?
- haskell - 导入 Control.Monad.Par 不工作