内置管道在我的组件中运行良好,但在我的自定义管道中却不行。除此之外,我的管道工作正常。自从我导入 Pipe 以来,我看不出可能是什么问题。
这是带有错误的代码:
import { Pipe, PipeTransform } from '@angular/core';
import { Perso } from './perso';
@Pipe({ name: 'startsWithPersoPipe' })
export class StartsWithPersoPipe implements PipeTransform {
transform(Persos: Perso[], search:string){
// without this if will crash as Persos is null until it gets its data from server
if(Persos == null) {
return null;
}
for(let perso of Persos){
console.log(perso.nom); // works fine
console.log(perso.nom | lowercase); // ORIGINAL EXCEPTION: ReferenceError: lowercase is not defined
}
return Persos.filter(p => (p.nom) && (p.nom).startsWith(search)); // works fine
}
}