我正在使用此代码进行选择:
为什么要生成此选项标记?
<option value="? string:feminino ?"></option>
它只发生在:
html:
<select id="gender" ng-model="genderMarked" ng-change="updateGender(genderMarked)" >
<option value="">Select a gender</option>
<option ng-value="collection.slug" ng-repeat="collection in collectionsGender">{{collection.title}}</option>
</select>
之后的HTML:
<select id="gender" ng-model="genderMarked" ng-change="updateGender(genderMarked)" class="ng-pristine ng-valid ng-touched"><option value="? string:feminino ?"></option>
<option value="? string:feminino ?"></option>
<option value="">Select a gender</option>
<option ng-value="collection.slug" ng-repeat="collection in collectionsGender" class="ng-binding ng-scope" value="masculino">Masculino</option>
<option ng-value="collection.slug" ng-repeat="collection in collectionsGender" class="ng-binding ng-scope" value="feminino">Feminino</option>
<option ng-value="collection.slug" ng-repeat="collection in collectionsGender" class="ng-binding ng-scope" value="infantil">Infantil</option>
</select>
我正在使用以下代码从网址(如果用户刷新页面)中获取性别标记:
if($stateParams.genderSlug){
$scope.genderMarked = $stateParams.genderSlug;
}else{
$scope.genderMarked = '';
}
答案 0 :(得分:1)
我发现ng-options
比重复的<option>
代码更容易使用。
试试这个
<select id="gender" ng-model="genderMarked" ng-change="updateGender(genderMarked)"
ng-options="collection.slug as collection.title for collection in collectionsGender">
<option value="">Select a gender</option>
</select>