我正在开发 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/