Using $index in ng-options directive in AngularJS

Last Reply one month ago By dharmendr

Posted one month 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  

You are viewing reply posted by: dharmendr one month ago.
Posted one month 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>