Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular JS: Pass a form's select option value as parameter on ng-submit="doStuff()"

Tags:

angularjs

I've simplified my code down to this:

<form ng-submit="doStuff($('select').val())">
  <select name="menu">
    <option value="foo">bar</option>
  </select>
</form>

When I submit the form, I want angular to pass <select>'s value is to the function doStuff(). Whats the best way to go about this?

like image 834
meiryo Avatar asked Aug 01 '13 07:08

meiryo


1 Answers

You dont need to pass the dropdown's value to the submit handler.

It would be available as $scope.menu inside the doStuff method.

Also, you should use angular's ng-options to fill the options inside the dropdown:

<form ng-submit="doStuff()">
<select ng-model="menu" ng-options="item.name for item in items">       
</select>

like image 129
AlwaysALearner Avatar answered Nov 15 '22 00:11

AlwaysALearner