【发布时间】:2018-02-02 18:51:51
【问题描述】:
我的问题是我想在放置名称过滤器的地方使用年份过滤器。
import { PipeTransform, Pipe } from '@angular/core';
import {index} from './index';
@Pipe({
name:'bookFilter',
})
export class BookFilterPipe implements PipeTransform
{
transform(value:index[],filterBy:any):index[]
{
filterBy=filterBy?filterBy.toLocaleLowerCase():null;
return filterBy?value.filter((book:index)=>
book.Name.toLocaleLowerCase().indexOf(filterBy)!==-1):value
// here I want to use year filter in that line.
}
}
【问题讨论】:
-
所以你在代码示例中使用
book.year而不是book.Name?问题是什么? -
另外请注意,使用管道进行过滤通常不是一个好主意。在此处查看文档:angular.io/guide/pipes#appendix-no-filterpipe-or-orderbypipe
-
是的,我使用了 book.year,但在那之后我可以放什么?
-
// book.Year.toFixed().indexOf(filterBy)!==-1):value
标签: angular angular2-forms angular2-services