我使用rorymadden.date -downdowns作为日期下拉列表,其中包括一个简单的选择,绑定到一个月数组:
<select name="dateFields.month" data-ng-model="dateFields.month" placeholder="Month" class="form-control" ng-options="month.value as month.name for month in months" ng-change="checkDate()" ng-disabled="disableFields">
<option ng-show="!dateFields.month" value="" translate="yes">#Apply.Month</option>
</select>
这将打印此HTML:
<select name="dateFields.month" data-ng-model="dateFields.month" placeholder="Month" class="form-control ng-valid ng-dirty ng-valid-parse ng-touched" ng-options="month.value as month.name for month in months" ng-change="checkDate()" ng-disabled="disableFields">
<option ng-show="!dateFields.month" value="" translate="yes" class="ng-hide" selected="selected"><span class="ng-scope">Month Test</span></option>
<option value="number:1" label="January">January</option>
<option value="number:2" label="February">February</option>
<option value="number:3" label="March">March</option>
<option value="number:4" label="April">April</option>
<option value="number:5" label="May">May</option>
<option value="number:6" label="June">June</option>
<option value="number:7" label="July">July</option>
<option value="number:8" label="August">August</option>
<option value="number:9" label="September">September</option>
<option value="number:10" label="October">October</option>
<option value="number:11" label="November">November</option>
<option value="number:12" label="December">December</option>
</select>
现在我想在选项中插入一个属性“translate”,以便使月份可以翻译。
所以我将选择更改为:
<select name="dateFields.month" data-ng-model="dateFields.month" placeholder="Month" class="form-control" ng-change="checkDate()" ng-disabled="disableFields">
<option ng-show="!dateFields.month" value="" translate="yes">#Apply.Month</option>
<option ng-repeat="month in months" value="{{month.value}}" translate="yes">{{month.name}}</option>
</select>
但现在我得到了无处插入的随机跨度,打破了翻译功能。生成的HTML是:
<select name="dateFields.month" data-ng-model="dateFields.month" placeholder="Month" class="form-control ng-valid ng-dirty ng-valid-parse ng-touched" ng-change="checkDate()" ng-disabled="disableFields">
<option ng-show="!dateFields.month" value="" translate="yes" class="ng-hide"><span class="ng-scope">Month Test</span></option>
<!-- ngRepeat: month in months -->
<option ng-repeat="month in months" value="1" translate="yes" class="ng-scope"><span class="ng-binding ng-scope">#Common.January</span></option>
<!-- end ngRepeat: month in months -->
<option ng-repeat="month in months" value="2" translate="yes" class="ng-scope"><span class="ng-binding ng-scope">#Common.February</span></option>
<!-- end ngRepeat: month in months -->
<option ng-repeat="month in months" value="3" translate="yes" class="ng-scope"><span class="ng-binding ng-scope">#Common.March</span></option>
<!-- end ngRepeat: month in months -->
<option ng-repeat="month in months" value="4" translate="yes" class="ng-scope"><span class="ng-binding ng-scope">#Common.April</span></option>
<!-- end ngRepeat: month in months -->
<option ng-repeat="month in months" value="5" translate="yes" class="ng-scope"><span class="ng-binding ng-scope">#Common.May</span></option>
<!-- end ngRepeat: month in months -->
<option ng-repeat="month in months" value="6" translate="yes" class="ng-scope"><span class="ng-binding ng-scope">#Common.June</span></option>
<!-- end ngRepeat: month in months -->
<option ng-repeat="month in months" value="7" translate="yes" class="ng-scope"><span class="ng-binding ng-scope">#Common.July</span></option>
<!-- end ngRepeat: month in months -->
<option ng-repeat="month in months" value="8" translate="yes" class="ng-scope"><span class="ng-binding ng-scope">#Common.August</span></option>
<!-- end ngRepeat: month in months -->
<option ng-repeat="month in months" value="9" translate="yes" class="ng-scope"><span class="ng-binding ng-scope">#Common.September</span></option>
<!-- end ngRepeat: month in months -->
<option ng-repeat="month in months" value="10" translate="yes" class="ng-scope"><span class="ng-binding ng-scope">#Common.October</span></option>
<!-- end ngRepeat: month in months -->
<option ng-repeat="month in months" value="11" translate="yes" class="ng-scope"><span class="ng-binding ng-scope">#Common.November</span></option>
<!-- end ngRepeat: month in months -->
<option ng-repeat="month in months" value="12" translate="yes" class="ng-scope"><span class="ng-binding ng-scope">#Common.December</span></option>
<!-- end ngRepeat: month in months -->
</select>
Angular究竟在做什么?为什么? 如何获得我希望它的预期输出:
<option ng-repeat="month in months" value="1" translate="yes" class="ng-scope">#Common.January</option>
有什么想法吗?
答案 0 :(得分:0)
您还将<option>January</option>
更改为<option>{{month.name}}</option>
,绑定到month.name正在为其功能添加范围。
您的翻译插件可能有一个翻译过滤器,因此请在选项{{month.name | translate}}
上使用该过滤器代替指令。这也为您提供了正确的字符串(&#34; january&#34;),而不是&#34; {{month.name}}&#34;。