生成角度未知标签

时间:2015-09-07 02:57:25

标签: javascript jquery html angularjs

我正在使用此代码进行选择:

为什么要生成此选项标记?

 <option value="? string:feminino ?"></option>

它只发生在:

  1. 我从选择
  2. 中选择一个选项
  3. 我使用性别
  4. 更新了网址
  5. 然后刷新。 (尝试使用网址上的选项自动选择)
  6. 之前的

    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 =  '';
            }
    

1 个答案:

答案 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>