정확하게 this 자습서와 같은 FlyingHeroesPipe 파이프를 만들었습니다.각도 4의 사용자 정의 파이프에서 '정의되지 않은'오류가 발생했습니다.
하지만 콘솔에서 TypeError: allHeroes is undefined
오류가 표시됩니다. 나는 어떻게해야합니까? 그물을 많이 검색했지만 모든 샘플은 내 사용자 지정 파이프와 같았지만 나 외에는 다른 사람들을 위해 작동합니다.
SRC/응용 프로그램/비행 - heroes.component.html (전단지)
<div *ngFor="let hero of (heroes | flyingHeroes)"> {{hero.name}} </div>
: 내 각 버전은 5.0.1
업데이트
내 코드입니다 src/app/flying-heroes.pipe.ts
(210)import { Pipe, PipeTransform } from '@angular/core';
import { Flyer } from './heroes';
@Pipe({ name: 'flyingHeroes' })
export class FlyingHeroesPipe implements PipeTransform {
transform(allHeroes: Flyer[]) {
return allHeroes.filter(hero => hero.canFly);
}
}
는
NgModule({
declarations: [
FlyingHeroesPipe ,
...
...
...
]
코드를 공유하십시오! –