node.js - 如何避免角度 ejs 选择选项标签中的黑色选项?
问题描述
您好,我正在使用 ng-repeat 来动态加载选项。
<select ng-init="NewPeriod[webhosting.index] || NewPeriod[webhosting.index]" style="font-size: 13px;" class="form-control" name="period" ng-model="NewPeriod[webhosting.index]" ng-change="updateHPeriod(webhosting.index)">
<option ng-repeat="period2 in Periods[webhosting.key] | orderBy: 'billingPeriod'" ng-selected="period2.billingPeriod == webhosting.period" autocomplete="off" value="{{period2.billingPeriod}}" ng-value="{{period2.billingPeriod}}" ng-if="period2.billingPeriod == 1">{{period2.billingPeriod}} month for ${{period2.amount.toFixed(2)}}
</option>
<option ng-repeat="period2 in Periods[webhosting.key] | orderBy: 'billingPeriod'" ng-selected="period2.billingPeriod == webhosting.period" autocomplete="off" value="{{period2.billingPeriod}}" ng-value="{{period2.billingPeriod}}" ng-if="period2.billingPeriod != 1">{{period2.billingPeriod}} months for ${{period2.amount.toFixed(2)}}
</option>
</select>
这是我的修复尝试(尝试初始化它但没有成功)
<select ng-init="NewPeriod[webhosting.index] || NewPeriod[webhosting.index] || Periods[webhosting.key][0] " style="font-size: 13px;" class="form-control" name="period" ng-model="NewPeriod[webhosting.index]" ng-change="updateHPeriod(webhosting.index)">
<option ng-repeat="period2 in Periods[webhosting.key] | orderBy: 'billingPeriod'" ng-selected="period2.billingPeriod == webhosting.period" autocomplete="off" value="{{period2.billingPeriod}}" ng-value="{{period2.billingPeriod}}" ng-if="period2.billingPeriod == 1">{{period2.billingPeriod}} month for ${{period2.amount.toFixed(2)}}
</option>
<option ng-repeat="period2 in Periods[webhosting.key] | orderBy: 'billingPeriod'" ng-selected="period2.billingPeriod == webhosting.period" autocomplete="off" value="{{period2.billingPeriod}}" ng-value="{{period2.billingPeriod}}" ng-if="period2.billingPeriod != 1">{{period2.billingPeriod}} months for ${{period2.amount.toFixed(2)}}
</option>
</select>
我看到空白值,即使没有空白值并且默认设置为空白。我怎样才能解决这个问题?
解决方案
要更改空白字段的显示/属性,您必须更改值为“”(空白)的选项。在您的选项上方添加以下行:
<option value="" ng-if="false"></option>
ng-if="false" 阻止它显示。
或者,如果您希望它说“选择一个...”等,您可以保留它并更改文本:
<option value="" selected> Select One...</option>
添加所选选项使其成为默认选项。
推荐阅读
- java - 如何在按钮 ActionListener 中到达外部 int?
- vue.js - 未捕获的 TypeError:Bootstrap 的 JavaScript 需要 jQuery。在使用 vujs2 时,必须在 Bootstrap 的 JavaScript 之前包含 jQuery
- reporting-services - SSRS 中的级联问题
- c++ - 包含在 2 个 gtest 文件中的静态内联关联集合引发读取访问冲突
- google-apps-script - 基于给定参考格式化单元格的更有效方法
- json - @ 符号在这个 [@][] ansible 代码中做了什么?
- python - 如果满足条件,则将行添加到数据框
- javascript - 根据媒体查询更改 React 导航栏行为和元素
- java - 无法执行 CommandLineRunner springboot。无法使用以下代码读取 json 数据。我如何修复它
- php - 下一个按钮条件不适用于 PHP 的分页