Using $index in ng-options directive in AngularJS

mahesh213
 
on Oct 13, 2020 12:10 AM
1742 Views

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  

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Oct 13, 2020 07:31 AM

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>

 

dharmendr
 
on Oct 17, 2020 07:53 AM

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>