我有一个使用 Codeigniter
和 AngularJs
开发的应用程序。我想在手动选择框中设置一个默认项,但是 Angular 添加了一个空的未定义项。
<select class="form-control" ng-model="newItem.is_active">
<option value="N" ng-selected="selected"><?php echo $this->lang->line('label_inactive'); ?></option>
<option value="Y"><?php echo $this->lang->line('label_active'); ?></option>
</select>
最佳答案
来自文档 ng-selected
If the expression is truthy, then special attribute "selected" will be set on the element
所以你可以做类似的事情
<option value="Y" ng-selected="newItem.is_active=='Y'"><?php echo $this->lang->line('label_active'); ?></option>
在 Controller 中
$scope.newItem = {
is_active: 'Y'
}
或
在 Controller 中你可以设置selected
值
$scope.selected = true; //put your selected condition
关于javascript - 使用angularjs在选择框中选择选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21072178/