0

select2 の値を取得できません。これは私のコードです:

<select id="categoryId" class="category"            
                        ng-model="selectedCategory"
                        ng-options="selectedCategories.name for selectedCategories in categories"
                        ng-change="selectedCategory()">
                        <option></option>
                    </select>

私のコントローラーでは、これを書きました:

    .....  

  function initializeSelect2 (){
        $category.select2({
                allowClear: true
        });
   }

   $scope.selectedCategory = function (){
        console.log('selectCategory: '+ $scope.selectedCategory);    
   }
4

2 に答える 2

0

新規参入者の場合、迅速かつ汚い解決策は、属性 ng-value を値に置き換え、ネイティブ JavaScript を使用して値を取得し、それをスコープ変数に割り当てることです。

<select id="categoryId" class="category"            
                    ng-model="selectedCategory"
                    ng-change="selectedCategory()">
                    <option ng-repeat="selectedCategories in categories" value="selectedCategories"></option>
</select>

そしてコントローラーで

$scope.selectedCategory.name = document.getElementById('categoryId').value;
于 2017-10-11T06:04:31.587 に答える