Using $index in ng-options directive in AngularJS

Last Reply 3 months ago By dharmendr

Posted 3 months ago

HI,

In below code url 

Filter DropDownList item based on condition Controller in AngularJS in ASP.Net MVC

I have done one change in product dropdown like below

<select class="input-sm form-control" select2="" ng-model="detail.Product"
    containercssclass="all" ng-options="c.PID as c.PName for c in detail.products[$index]">
    <option value="">Select Product</option>
</select>

Could you please help me with above code changes  

Posted 3 months ago

Hi mahesh213,

You can't apply index for select. You have to use $index in option tag like below.

Refer below code.

<select class="input-sm form-control" select2="" ng-model="detail.Product"
        containercssclass="all">
    <option value="">Select Product</option>
    <option ng-repeat="p in detail.products track by $index" value="{{$index}}">
        {{p.PName}}
    </option>
</select>

 


Posted 3 months ago

Use below.

<select class="input-sm form-control" select2="" ng-model="detail.Product"
    containercssclass="all" ng-options="c.PID as c.PName for c in detail.products">
    <option value="">Select Product</option>
</select>