我似乎无法解决此问题。我已经在app.module.ts中导入并将其放入'声明'。
app.module.ts中的
import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
//ionic-native
import { NativeStorage } from '@ionic-native/native-storage';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
//pipe
import { HoursMinutesSecondsPipe } from '../pipes/hours-minutes-
seconds/hours-minutes-seconds';
@NgModule({
declarations: [
MyApp,
HoursMinutesSecondsPipe
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp, {
platforms: {
android: {
tabsPlacement: 'top'
}
}
}),
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
NativeStorage,
]
})
export class AppModule {}
用法:
<ion-card class="card-container" (click)="onTimer()">
<img src="assets/imgs/wp1.png"/>
<div class="card-title">Time Smoke Free</div>
<div class="card-subtitle">{{ seconds | hoursMinutesSeconds }}</div>
</ion-card>
以小时 - 分 - 秒为单位
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'hoursMinutesSeconds',
})
export class HoursMinutesSecondsPipe implements PipeTransform {
transform(value, args?) {
let minutes = Math.floor(value / 60);
let hours = Math.floor(minutes / 60);
let seconds = Math.floor(value % 60);
let timeString = hours + 'hrs ' + minutes + 'mins ' + seconds + 'secs';
return timeString;
}
}
错误: 未捕获(承诺):错误:模板解析错误: 管道小时数秒数&#39;无法找到(&#34; imgs / wp1.png&#34; /&gt; 时间无烟 {{[ERROR - &gt;]秒| hoursMinutesSeconds}}
答案 0 :(得分:23)
使用此CLI pipe
创建ionic generate pipe HoursMinutesSeconds
时,它将创建一个名为pipes.module.ts
的共享模块。因此,您需要在页面的模块文件中使用import
PipesModule
模块。
让我们认为页面是my-view
然后;
MY-view.module.ts
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { MyViewPage } from './my-view';
import { PipesModule } from '../../pipes/pipes.module';//<--- here
@NgModule({
declarations: [
MyViewPage,
],
imports: [
IonicPageModule.forChild(BudgetGroupViewPage),
PipesModule // <--- here
],
})
export class MyViewPageModule { }