question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Library fails to work if class is used instead of object for data input

See original GitHub issue

Hello. 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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Eivysescommented, Jan 7, 2020

@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

0reactions
gmerabishvilicommented, Dec 28, 2020

Hello @Eivyses. The issue is fixed. Please upgrade to latest 2.0.2 version. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - "A project with an Output type of Class Library cannot be ...
I built the project successfully, but when I try to debug the project I get this message: A project with an Output type...
Read more >
DataInputStream (Java Platform SE 7 ) - Oracle Help Center
A data input stream lets an application read primitive Java data types from an underlying input stream in a machine-independent way.
Read more >
Data Classes in Python 3.7+ (Guide)
The problem is that all instances of Deck will use the same list object as the default value of the .cards property. This...
Read more >
Classes - Object-Oriented Programming in Python
We have already seen how we can use a dictionary to group related data together, ... When we call the class object, a...
Read more >
9. Objects, Case Classes, and Traits - Learning Scala [Book]
Use the object keyword, in place of class , to define an object. ... I/O functions are those that work with external data,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found