Angular JS: pass the value of the form selection parameter as a parameter to ng-submit = "doStuff ()"

I simplified my code 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 the <select> value to the doStuff() function. What is the best way to do this?

+6
source share
1 answer

You do not need to pass the outlier to the submit handler.

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

In addition, you should use angular ng-options to populate the options inside the dropdown menu:

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

+12
source

Source: https://habr.com/ru/post/950795/


All Articles