orizens / ngx-typeahead

A simple but yet powerful typeahead component for Angular (css framework agnostic)
https://www.npmjs.com/package/ngx-typeahead
MIT License
61 stars 29 forks source link

results.map is not a function #28

Open matthewdolman opened 6 years ago

matthewdolman commented 6 years ago

I have been using the 'http' Api.

But when the response comes back from the server I get there error

ERROR TypeError: results.map is not a function

The structure of my returned object is

{
  result: 1,
  items: [
    {
      name: "matthew",
      age: "21"
    },
    {....
    }
  ]
}
coryschires commented 5 years ago

We encountered this same problem. The problem is that ngx-typeahead expects the api to return an array – not an object (as shown in your snippet above).

To fix this, afaik, you need to transform the API response on your server so that it responds with an array rather than an object.

Feature Idea: It would be cool if ngx-typeahead let us define a callback function where we could transform the raw API response (e.g. from an object into an array) before handing the data to ngx-typeahead. This way, you could manage everything on the client.

Or... If not that, a more descriptive error message would probably be helpful.

thebpmgroup commented 5 years ago

Any chance you can give an example of what a "good" array would look like? Looking at the code and trying to guess is taking me nowhere fast.