Reputation:
Is there a way where I can access the selected item in drop down list in ember via controller? Give me a short example.
Thanks in advance!
Upvotes: 0
Views: 2708
Reputation: 18672
You can create a drop down list by using HTML <select>
:
Controller:
import Ember from 'ember';
export default Ember.Controller.extend({
options: ['red', 'green', 'blue'],
selectedColor: null
});
Template:
Pick your favourite color:
<br/>
<select onchange={{action (mut selectedColor) value='target.value'}}>
{{#each options as |option|}}
<option value={{option}}>{{option}}</option>
{{/each}}
</select>
<br/><br/>
Your favourite color is: <b>{{selectedColor}}</b>
Upvotes: 1