角JS:通过一种形式的选择选项值作为参数的NG-提交= QUOT; doStuff()"选项、形式、参数、JS

2023-09-13 04:52:39 作者:白菜先生请留步i

我已经简化我的code到这一点:

I've simplified my code down to this:

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

当我提交表单,我想角传&LT;选择&GT; 的价值是对函数 doStuff()。最新最好的方式去吗?

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?

推荐答案

您不需要向下拉的值传递给提交处理。

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

这将是作为 $ scope.menu 的doStuff方法中。

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

此外,你应该使用角的 NG-选项,以填补下拉里面的选项:

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>