I can't seem any error regarding this problem. I already import in app.module.ts and put it in 'declaration'.
in 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 {}
Usage:
<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>
in hours-minutes-seconds.ts
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;
}
}
Error: Uncaught (in promise): Error: Template parse errors: The pipe 'hoursMinutesSeconds' could not be found ("imgs/wp1.png"/> Time Smoke Free {{ [ERROR ->]seconds | hoursMinutesSeconds }}
When you create a pipe
using this CLI ionic generate pipe HoursMinutesSeconds
it'll create a shared module called pipes.module.ts
. So you need to import
PipesModule
module inside your page's module file.
Let's think that page is my-view
then;
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 { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With