カスタムパイプを作成していくつかの項目を隠そうとしています。角度2のフィルタパイプ
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]
})
は私の項目は、真または偽とすることができる、目に見える性質を有しています。
何も表示されませんが、私のパイプに何か問題がありますか?
私は、私はパイプコードを変更したときので、私のパイプが機能していると思う:
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;
}
}
これは、すべての項目が表示されます。
おかげ
パイプを使用しているコンポーネントに 'pipes:[ShowPipe]'を追加しましたか?あなたのコードに何か間違ったものは見当たりません。 –
更新されたコード... – tony
あなたがそれを不純なパイプにするとどうなりますか? '@Pipe({ name: 'showfilter'、pure:false }' – PierreDuc