【发布时间】:2017-12-17 05:47:40
【问题描述】:
我正在使用 ionic 并创建了一个自定义管道,该管道接受一个表示图像数据的对象并返回该图像的 URL。
管道文件长这样……
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'eventImageLink',
})
export class EventImageLinkPipe implements PipeTransform {
/**
* Takes a value and makes it lowercase.
*/
transform(value: string, ...args) {
if(value){
return `//res.cloudinary.com/***/image/upload/w_${window.screen.width},d_item_placeholder_e0lign.jpg/${value.image_version}/${args[0]}/${value.original_image_name}`;
}
}
}
我在pipes 文件夹中创建了一个pipes.module.ts 文件,用于导入我的管道...
import { NgModule } from '@angular/core';
import { EventImageLinkPipe } from './event-image-link/event-image-link';
@NgModule({
declarations: [
EventImageLinkPipe
],
imports: [
],
exports: [
EventImageLinkPipe
]
})
export class PipesModule {}
现在,在我将 PipesModule 导入组件以供使用之前,我收到以下错误...
打字稿错误
“字符串”类型上不存在属性“图像版本”。
我什至还没有尝试使用它时,我不明白为什么会出现这个错误,这真的很烦人。有人可以解释为什么要执行管道,以及当我还没有将任何数据传递到管道中时如何防止抛出此错误?
【问题讨论】:
标签: javascript angular typescript ionic3