Library fails to work if class is used instead of object for data input
See original GitHub issueHello. Sorry if I write this in bad structure, but i haven’t done it before. So, there’s a bug in autocomplete with classes. If i provide interface like this:
export interface Test {
id: number
name: string
}
And after that I initialize interface and give it as data to autocomplete:
testData: Test[] = [
{
id: 2,
name: 'hello'
},
{
id: 4,
name: 'test'
}]
Everything works as expected. But, If i were to replace interface with class
export class Test {
id: number;
name: string;
constructor(id: number, name: string){
this.id = id;
this.name = name;
}
}
And after that and give it as data to autocomplete:
testData: Test[] = [];
testData.push(new Test(2, 'hello'));
testData.push(new Test(4, 'test'));
Autocomplete simply won’t work. Nothing will be shown. I did go through code and found out the reason it is not working on line https://github.com/gmerabishvili/angular-ng-autocomplete/blob/0ebdefb27635fd6382246ab2b041be0c00b1aaaa/projects/autocomplete-lib/src/lib/autocomplete/autocomplete.component.ts#L234
When i give concrete class the item.constructor contains:
ƒ Test(id, name) {
this.id = id;
this.name = name;
}
instead of expected
ƒ Object() { [native code] }
My solution is to change && item.constructor === Object into && item instanceof Object
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)

Top Related StackOverflow Question
@gmerabishvili hey. I did create a demo, but i can’t share a full link to it. Open plunker and paste to it all the code from this file demo_project.zip
Hello @Eivyses. The issue is fixed. Please upgrade to latest 2.0.2 version. Thank you!