How to know whether an item from the dropdown has been selected in angular ui typeahead?

By : Bjarte
Source: Stackoverflow.com
Question!

http://plnkr.co/edit/zuhSEg0lGtR4vzPGJmak?p=preview

How should I make the button inactive? It should only be active when a complete city name has been selected from the dropdown of the typeahead e.g. "Alabama" and the button should be inactive in case something is typed, but is not a complete name from the list e.g."Alab"

http://angular-ui.github.io/bootstrap/#/typeahead

By : Bjarte


Answers

http://plnkr.co/edit/pdiCre996CnknWqQZgzV?p=preview

Here I've disabled the button if the selected value is not in the array of states. I know that if the array is large this could be a performance hit.

jQuery has a function $.inArray

or Underscore has a _.contains(list,val) function if you want to use those libraries instead of extending the Array javascript object.



This video can help you solving your question :)
By: admin