No Directive annotation found on
@Pipe({name: 'myPipe'}) // this one is use in your html {{ ... | myPipe }}
export class MyPipe implements PipeTransform {
transform(input:any) : any {
// Do stuffs
return stuffs;
}
}
Has then to be declared in the “declarations” part of your app.module.ts
You could place your pipes in src/pipes (if folder doesn’t exists, just create it on your filesystem)
Yes thanks, it worked but we need to add @Injectable (). Example:
@Pipe({name: ‘myPipe’}) // this one is use in your html {{ … | myPipe }}
@Injectable()
export class MyPipe implements PipeTransform {
transform(input:any) : any {
// Do stuffs
return stuffs;
}
}
Really?
I didn’t and it seems to work
really do not need @Injectable ().
I just tested and it works perfectly.
The command: ionic generate pipe mypipe, creates a pipe as follows:
import { Injectable, Pipe } from ‘@angular/core’;
@Pipe({
name: ‘mypipe’
})
@Injectable()
export class Mypipe {
transform(value, args) {
value = value + ‘’; // make sure it’s a string
return value.toLowerCase();
}
}
Cool. Quickly checked the angular2 documentation, they don’t use injectables neither (see ExponentialStrengthPipe example)
so,i’m using “ionic-angular”: "^2.0.0-rc.1"
and this will work:
@Pipe({
name:"YourCoolPipe"
})
export class YourCoolPipe implements PipeTransform{
transform(input:any,args:any){
//dosomething here
return //yourResult;
}
}
and finally,you need to add this pipe to your @NgModule right in declarations arrays
hope this will help you
Use the generators, saves you from quite some trouble.
except you need to remove the args in the filter call if you dont use them, otherwise you’ll get errors