Empty parameter field in Select tag - Angualr js

I am getting empty Option field in select tag.

My code is shown below:

openSelectBoxModel="47"
openSelectList=[{id:""47",name:"text"}];
valuekey="id";
titlekey="name";

<select id="reportOpenSelectBoxSingle" size="6" ng-style='selectStyle' class="openSelectBox" ng-model="openSelectBoxModel" ng-change="changeFn()" >
<option ng-selected="openSelectBoxModel===item[valueKey]" ng-repeat="item in openSelectList" id="" ng-value="{{item[valueKey]}}" ng-title="{{item[titleKey]}}" ng-bind="item[titleKey]"></option>
</select>

      

Please help me to solve this problem.

+3


source to share


1 answer


You shouldn't be using ng-selected with ng-model.

Before displaying it, you need to bind the selected item to your ng model.

// Also, instead of ng-repeat, you should use ng-option
As far as performance is concerned: ng-options does not create child scopes for each iteration. When angular is doing its digest, your ng-repeat will slow it down. If you have a list with hundreds of items, you will feel the difference.



<select id="reportOpenSelectBoxSingle" 
        size="6" 
        ng-style='selectStyle' 
        class="openSelectBox" 
        ng-model="openSelectBoxModel" 
        ng-change="changeFn()" >
     <option ng-repeat="item in openSelectList" 
             value="{{item[valueKey]}}" 
             title="{{item[titleKey]}}" 
             ng-bind="item[titleKey]">
     </option>
</select>

      

Also, you need to declare your variables inside the controller:

$scope.openSelectBoxModel="47";
$scope.openSelectList=[{id:"47",name:"text"}];
$scope.valuekey="id";
$scope.titlekey="name";

      

+1


source







All Articles