【发布时间】:2020-04-30 18:21:36
【问题描述】:
我从 API 调用数据,其中包括图像但不是全部,因此我创建了一个管道来处理没有图像的数据。
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'noImg'
})
export class NoImgPipe implements PipeTransform {
transform(image: any): string {
if (image === null ) {
return '/assets/Images/no-img.jpg' ;
// Regresa la imagen por defecto no images
} else {
return image;
}
}
}
它在本地主机上运行良好,但是当我使用 ng build --prod 编译项目并托管我的应用程序时,管道不起作用。
我还在路由中激活了 useHash 并删除了 /in the baseHref=""
【问题讨论】:
-
“管道不工作”不是很具体。您的浏览器开发控制台中是否有一些错误或请求的网络问题?
-
去掉前面的
/ -
我的意思是,在生产中,当我托管应用程序时,它不会显示 no-image.jpg 而是经典的无图像 html 图标,控制台中没有错误,它编译得很好。
标签: angular typescript localhost pipe web-hosting