diff --git a/.gitignore b/.gitignore index 3422917e..01a12946 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,5 @@ testem.log #System Files .DS_Store Thumbs.db + +yarn.lock diff --git a/examples/ng-cli/src/app/shared/ngx-filter.pipe.spec.ts b/examples/ng-cli/src/app/shared/ngx-filter.pipe.spec.ts index 62ad0d15..dd42173c 100644 --- a/examples/ng-cli/src/app/shared/ngx-filter.pipe.spec.ts +++ b/examples/ng-cli/src/app/shared/ngx-filter.pipe.spec.ts @@ -100,6 +100,36 @@ describe('Pipe: FilterPipe', () => { expect(pipe.transform(objects, { name: 'Qwe123' })).toEqual([]); }); + it('should get value from getter defined in class ancestor', () => { + class User { + firstName: string; + lastName: string; + + constructor(first: string, last: string) { + this.firstName = first; + this.lastName = last; + } + + get name() { + return `${ this.firstName } ${ this.lastName }`; + } + } + + class UserEx extends User { + + } + + const userA = new UserEx('Abc', '123'); + const objects = [ + userA, + new UserEx('Qwe', '123') + ]; + + expect(pipe.transform(objects, { name: '123' })).toEqual(objects); + expect(pipe.transform(objects, { name: 'Abc 123' })).toEqual([userA]); + expect(pipe.transform(objects, { name: 'Qwe123' })).toEqual([]); + }); + it('should filter by empty filter string', () => { const objects = [ 'test', diff --git a/examples/ng-cli/src/app/shared/ngx-filter.pipe.ts b/examples/ng-cli/src/app/shared/ngx-filter.pipe.ts index eeca73ca..77bd2400 100644 --- a/examples/ng-cli/src/app/shared/ngx-filter.pipe.ts +++ b/examples/ng-cli/src/app/shared/ngx-filter.pipe.ts @@ -37,7 +37,16 @@ export class FilterPipe { continue; } - if (!value.hasOwnProperty(key) && !Object.getOwnPropertyDescriptor(Object.getPrototypeOf(value), key)) { + let walker = value; + let found = false; + do { + if (walker.hasOwnProperty(key) || Object.getOwnPropertyDescriptor(walker, key)) { + found = true; + break; + } + } while (walker = Object.getPrototypeOf(walker)); + + if (!found) { return false; } @@ -148,4 +157,4 @@ export class FilterPipe { return array.filter(this.filterDefault(filter)); } -} \ No newline at end of file +}