首页 > 解决方案 > 如何避免角度 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>

我看到空白值,即使没有空白值并且默认设置为空白。我怎样才能解决这个问题?

标签: node.jsangularjsejstwo-way-binding

解决方案


要更改空白字段的显示/属性,您必须更改值为“”(空白)的选项。在您的选项上方添加以下行:

<option value="" ng-if="false"></option>

ng-if="false" 阻止它显示。

或者,如果您希望它说“选择一个...”等,您可以保留它并更改文本:

<option value="" selected> Select One...</option>

添加所选选项使其成为默认选项。


推荐阅读