Siyfion/angular-typeahead

Populate AngularJS Typeahead Input with data pulled from datafactory

Closed this issue · 2 comments

I'm having a little trouble here with implementing typeahead in angularjs on a watched data set. When I use a data set local to the controller it works just fine but if I setup a watcher for a data set pulled from my data service, nothing populates the typeahead input box. If I reference the data set in the html under the input box, I can see the data pulled from the data service tho.

Any help would be appreciated. Here's a plunker reproduction of the problem: http://plnkr.co/edit/PCyZHF?p=preview

I think the issue is with the "vm.numbersDataSet" model, you never update it after the list is updated. I've never used typeahead or Bloodhound but it seems like when you create the new instance of Bloodhound and then create "vm.numbersDataSet" changes to the vm.numberList array don't change the the Bloodhound instance.

I also am not aware of a way to access the "local" attribute in the Bloodhound instance to automatically update it so the only solution I could come up with was to manually update the "vm.numbersDataSet" model in the "updateNumberList()" function.
capture

I changed the initial bloodhound call to use "dataService.fetchNumbersList()". Since you're already watching the numberList you don't need to reference it again
capture2

Here's the plunker I made. Hope this helps some and sorry I couldn't make it more elegant. Will keep tinkering.
http://plnkr.co/edit/Zq2Tpuws1lvN4Taz6Fai?p=info

hmil commented

@chrisjmccrum Did that answer your question?
It looks like the issue you are running into has little to do with the way angular-typeahead works.