Tenho o código abaixo, idêntico ao da aula, porém não funciona
import { Pipe, PipeTransform } from "@angular/core";
import { Photo } from "../photo/photo";
@Pipe({
name: 'filterByDescription'
})
export class FilterByDescription implements PipeTransform {
transform(photos: Photo[], descriptionQuery: string) {
descriptionQuery = descriptionQuery
.trim()
.toLowerCase();
if(descriptionQuery) {
return photos.filter(photo =>
photo.description.toLowerCase().includes(descriptionQuery));
} else {
return photos;
}
}
}
Stack do erro
PhotoListComponent.html:12 ERROR TypeError: Cannot read property 'trim' of undefined
at FilterByDescription.push../src/app/photos/photo-list/filter-by-description.pipe.ts.FilterByDescription.transform (filter-by-description.pipe.ts:11)
at checkAndUpdatePureExpressionInline (core.js:9942)
at checkAndUpdateNodeInline (core.js:10511)
at checkAndUpdateNode (core.js:10469)
at debugCheckAndUpdateNode (core.js:11102)
at debugCheckDirectivesFn (core.js:11062)
at Object.eval [as updateDirectives] (PhotoListComponent.html:12)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:11054)
at checkAndUpdateView (core.js:10451)
at callViewAction (core.js:10692)