Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm working with AngularJS and i want to use the directive ng-click when an element of a datalist (html5) is selected.

Here is an example of my actual code:

<label>Search</label>
<input type="text" class="input-search" list="datalistcit"
ng-change="changeQuery(queryCity)" ng-model="queryCity" />
<datalist id="datalistcit">
   <option ng-repeat="city in cities" ng-click="goCity(city)" value="{{city.name}}">
   </option>
</datalist>

It doesn't work, never execute the js method goCity.. any idea?

Thanks!

share|improve this question
    
You probably need an ng-model in your datalist. I know that it wouldn't work if it were a select tag without an ng-model. –  Zack Argyle Mar 12 at 3:53
    
not work.. here is en example jsfiddle.net/lukers/MCnL2 –  lukersf Mar 12 at 23:31
    
Try my answer here. stackoverflow.com/questions/23112662/… –  Aye Mon Chit Aug 12 at 5:46

1 Answer 1

datalist is same as select, you don't put the event handler in option, you put the event handler in select or input. Also you don't use ng-click, you use ng-change for this.

share|improve this answer
    
i put the event in datalist and not work.. here is en example jsfiddle.net/lukers/MCnL2 –  lukersf Mar 12 at 23:11
    
I said both ng-change, ng-model needs put in input or select, Do Not put in datalist or option. –  wayne Mar 13 at 5:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.