我有一个选择,其中包含从服务器获取的选项
<div class="form-group">
<label for="exampleInputEmail1">Terminal Type</label>
<select ng-model="terminal.terminalType" id="terminaltype" class="form-control" ng-options="type.name for type in types">
</select>
</div>
但是我如何在 Controller 中设置选项。 我用过:
$("#terminaltype").val($scope.types[0]);
和
document.getElementById("terminaltype").options[i];
但是它不起作用。请帮助我
最佳答案
不能在模型中设置值吗?
您有ng-model="terminal.terminalType"
在 Controller 内,您只需为项目设置一个值。
$scope.terminal.terminalType = "someValue";
避免将 JQuery 和 Angular 混合在一起。
关于javascript - 如何在 Angular Controller 中选择对象选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31917717/