【发布时间】:2019-03-17 05:50:37
【问题描述】:
我创建了一些可重用的组件,可以在需要使用管道的其他页面中使用。但是,当我尝试导入管道时,html 不知道。它在下面返回一个错误。
错误:模板解析错误:找不到管道“图像”
我知道在 Pages 中使用管道是可行的,但是如何使用管道处理组件?
进一步解释这一点。我有一个名为 accounts.ts 的页面,该页面使用了 <orders> component,我将其呈现为这样。
<orders (viewOrder)="viewAccount($event)" [orders]="orderCancelled" *ngIf="accountsHasLoaded"></orders>
我在该页面的ngModule 中声明了这一点。
@NgModule({
declarations: [
AccountPage,
],
imports: [
PipesModule,
NgCalendarModule,
ComponentsModule,
IonicPageModule.forChild(AccountPage),
],
})
这是 accounts 页面的 ngModule,将使用 orders 组件。
下面是我的 component.ts
中的代码@Component({
selector: 'orders',
templateUrl: 'orders.html',
providers: [
ImagePipe
]
})
当我将提供程序中的 ImagePipe 替换为 PipesModule 时,它仍然不起作用。
在我的html
中 <img [src]="order?.client?.image?.url | image: 'original'" onError="this.src='assets/imgs/No_Image_Available.jpg';">
管道图像适用于 页面,但是当我尝试在组件中使用它时它不起作用。
这是我的管道模块下面
import { NgModule } from '@angular/core';
import { ChatDatePipe } from './chat-date/chat-date';
import { MomentPipe } from './moment/moment';
import { DatepickerFormatPipe } from './datepicker-format/datepicker-format';
import { ImagePipe } from './image/image';
@NgModule({
declarations: [
ChatDatePipe,
MomentPipe,
DatepickerFormatPipe,
ImagePipe
],
imports: [],
exports: [
ChatDatePipe,
MomentPipe,
DatepickerFormatPipe,
ImagePipe
],
providers: [
ImagePipe
]
})
export class PipesModule { }
如果有人可以提供帮助,我们将不胜感激。 提前致谢。
【问题讨论】:
-
发布您的图像管道代码
-
您是否尝试使用“ionic generate pipe”命令并查看默认实现如何工作?
标签: angular ionic-framework ionic3 pipe components