javascript - 如何获取select中选中的值?

标签 javascript angularjs

我正在开发 angularjs 表单。我想将definition.clazz 传递给js 函数。在 Controller 中,我有一个 js 函数,例如:

$scope.createData=function(clazz){
// do stuff
}

这是表单的片段:

<select  class="form-control" id="type" name="type" ng-model="definition.clazz">
    <option value="PrimitiveType" 
            ng-selected="type.type=='PRIMITIVE'">
        PrimitiveType
    </option>
    <option value="EnumerationType"
            ng-selected="type.type=='ENUM'">
        EnumerationType
    </option>
</select> 
<button type="button" 
        class="btn btn-primary"
        ng-click="createData(definition.clazz)">
    Create Data   
</button>

当我单击“创建数据”按钮时,未设置ng-model。即使我在控制台日志中打印 definition.clazz 。 如何获取select的select值? 谢谢。

最佳答案

您是否尝试过使用 ng-options 来代替?我的猜测是 ng-model 可能需要在选择上这样做。

关于javascript - 如何获取select中选中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27706840/

相关文章:

javascript - AngularJS - 持续监视集合

javascript - 将类更改为 div 中的所有图像 - jQuery

javascript - 收到 fcm 推送通知后更新页面上的 View 并且我在同一页面上

javascript - 延迟显示 "no Javascript"警告?

javascript - 在angularjs中注入(inject)依赖项的可维护方式

javascript - 等待 promise 在不同的 Controller 中得到解决

javascript - 如何在 JavaScript 中检索 HttpResponseMessage 文件名

javascript - 使用 JQuery 和数据属性进行多重过滤

javascript - -nan 在 C++ 中是什么意思?为什么 pow(-4, -2.1) 返回 -nan?

javascript - AngularJS Controller 对象未定义