Trying to write a custom pipe to hide some items.
import { Pipe } from '@angular/core';
// Tell Angular2 we're creating a Pipe with TypeScript decorators
@Pipe({
name: 'showfilter'
})
export class ShowPipe {
transform(value) {
return value.filter(item => {
return item.visible == true;
});
}
}
HTML
<flights *ngFor="let item of items | showfilter">
</flights>
COMPONENT
import { ShowPipe } from '../pipes/show.pipe';
@Component({
selector: 'results',
templateUrl: 'app/templates/results.html',
pipes: [PaginatePipe, ShowPipe]
})
My item has the property of visible, which can be true or false.
However nothing showing, is there something wrong with my pipe?
I think my pipe is working because when I change the pipe code to:
import { Pipe } from '@angular/core';
// Tell Angular2 we're creating a Pipe with TypeScript decorators
@Pipe({
name: 'showfilter'
})
export class ShowPipe {
transform(value) {
return value;
}
}
It will show all items.
Thanks
pipes: [ShowPipe]
to the component where you are using the pipe? I can't see anything wrong in your code. – Günter Zöchbauer@Pipe({ name: 'showfilter', pure : false })
– Poul Kruijt