Issue
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'distance'
})
export class DistancePipe implements PipeTransform {
transform(distance: number, ...args: any[]): string {
return distance.toFixed(2) + "m";
}
}
My pipe. I generated it with ionic g pipe pipes/distance
import { DistancePipe } from './pipes/distance.pipe';
@NgModule({
declarations: [AppComponent, DistancePipe],
entryComponents: [],
imports: [
BrowserModule,
IonicModule.forRoot(),
AppRoutingModule,
IonicStorageModule.forRoot(),
HttpClientModule
],
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
Geolocation,
ImagePicker ,
FilePath
],
bootstrap: [AppComponent]
})
export class AppModule {}
My AppModule. It adds the Pipe automatically.
{{object.distance | distance}}
This is how I use it. on object.page.html
My error is:
core.js:4197 ERROR Error: The pipe 'distance' could not be found!
How can I solve it? Should it not work out of the box?
Solution
I had to add the pipe to the object.module.ts.
I add it as a declaration.
Answered By - Matheus M.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.