How do I get "select" event to work?


#1

I cannot find further information in the documentation other than the markup.

<div class="list">
  <label class="item item-input item-select">
    <div class="input-label">
      Lightsaber
    </div>
    <select>
      <option>Blue</option>
      <option selected>Green</option>
      <option>Red</option>
    </select>
  </label>
</div>

Is there a CodePen or something that describes how to get which item the user selected?

Thank you!


#2

you could use ng-modal it will then do a 2-way databinding.

devine a variable in controller ($scope.selectValue)
and in html use :

<select ng-modal="selectValue">
      <option>Blue</option>
      <option selected>Green</option>
      <option>Red</option>
    </select> 

dont forget to bind controller.

if you want to try something different:


#3

OK, I see, that’s cool. So I now have this…

  • How do I set the initial value.
  • How do I get the new value that is selected?

Thanks!


#4

as you do it right now he wants an item form $scope.numbers.

but i think you just want to pass a key and then select.
For this you have to assign the key with ng-option like this

ng-options="number.key as number.value for number in numbers"

here an examle:

note : using key = ‘3’ you have to set $scope.myNumber = ‘3’; (with upper quote)


#5

OK, that’s working great too now. Thank you.

But how do I get the new value that they changed to in the controller? I need to act on that new value?

Thanks!


#6

when you change the value in the select it will be saved in myNumber.

do you need to do something when value is changed?


#7

Yes, I need to save that value to localstorage but don’t know how to tap into the event of the select.


#8

I also need to fire some action onchange of the select, one way could be to use ng-model for binding something like ‘currentselected’ in scope, then do $scope.$watch(‘currentselected’ …

How is the common angular way? is this not recommended?


#9

I added this:

ng-change=“valueChanged()”


#10

i have to write 20 letter minimun:

thats it, thanks!