user7637934
user7637934

Reputation:

Drop-down list in Ember;

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

Answers (1)

Daniel
Daniel

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>

Live demo.

Upvotes: 1

Related Questions