2

我正在尝试使用自定义管道声明来搜索和过滤列表中的元素。但我收到以下错误,无法弄清楚原因。(我使用 angular2-seed 项目作为基础项目)

错误:

platform-browser.umd.js:1900 EXCEPTION: Error: Uncaught (in promise): No Pipe decorator found on SearchPipe

管道类代码:

import { Pipe,PipeTransform } from 'angular2/core';
import { User } from './user';
@Pipe({
   name: 'search'
})
export class SearchPipe implements PipeTransform {
transform(value, [searchterm]) {
   if (value === undefined) {
      return value;
   } else {
      return value.filter((user:User) => user.Name.toLowerCase().includes(searchterm.toLowerCase()));
   }
 }
}

组件类代码:

import {SearchPipe} from './users.search-pipe';

@Component({
    selector: 'users',
    moduleId: module.id,
    templateUrl: './users.component.html',
    styleUrls: ['./users.component.css'],
    pipes: [SearchPipe]
})

export class UsersComponent implements OnInit {
    .........
}
4

0 回答 0