角JS:通过一种形式的选择选项值作为参数的NG-提交= QUOT; doStuff()" [英] Angular JS: Pass a form's select option value as parameter on ng-submit="doStuff()"

查看:131
本文介绍了角JS:通过一种形式的选择选项值作为参数的NG-提交= QUOT; doStuff()"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经简化我的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>

这篇关于角JS:通过一种形式的选择选项值作为参数的NG-提交= QUOT; doStuff()&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆