Skip to content

Instantly share code, notes, and snippets.

@ugurayan
Created September 23, 2017 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ugurayan/f51436e737838df52d92ad70241a5748 to your computer and use it in GitHub Desktop.
Save ugurayan/f51436e737838df52d92ad70241a5748 to your computer and use it in GitHub Desktop.
Case #1: Import only to app.module.ts a Pipe file
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import {MyPipe} from '../pipes/my/my';
@NgModule({
declarations: [
MyApp,
HomePage,
MyPipe
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
<ion-header>
<ion-navbar>
<ion-title>
{{'home' | myPipe}}
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<a (click)="openPage(1)"> Page #1 </a>
<a (click)="openPage(2)"> Page #2 </a>
</ion-content>
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'myPipe',
})
export class MyPipe implements PipeTransform {
/**
* Takes a value and makes it lowercase.
*/
transform(value: string, ...args) {
return value + ' is piped. OK!';
}
}
<ion-header>
<ion-navbar>
<ion-title>page1</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
{{'test1' | myPipe}}
</ion-content>
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { Page1Page } from './page1';
// import {MyPipe} from "../../pipes/my/my";
@NgModule({
declarations: [
Page1Page,
// MyPipe
],
imports: [
IonicPageModule.forChild(Page1Page),
],
})
export class Page1PageModule {}
<ion-header>
<ion-navbar>
<ion-title>page2</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
{{'test2' | myPipe}}
</ion-content>
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { Page2Page } from './page2';
// import {MyPipe} from "../../pipes/my/my";
@NgModule({
declarations: [
Page2Page,
// MyPipe
],
imports: [
IonicPageModule.forChild(Page2Page),
],
})
export class Page2PageModule {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment