JOhns
JOhns

Reputation: 339

how to $Index get from Javascript side

how to Checked value from $index base. suppose in textboxStart Index and TextboxEnd . when user enter Start index 5 and End Index 10 , checkbox automatically checked, from 5 To 10 Index. please help me

<tr ng-repeat="item in MyList">
    <td>{{$index}}</td>
    <td>
        <label class="mdl-checkbox mdl-js-checkbox" for="checkbox33">
            <input autocomplete="off" ng-model="item.checked" 
                   type="checkbox" id="checkbox33"
                   class="mdl-checkbox__input" unchecked>
            {{CheckItems()}}
        </label>
    <td>{{item.Name}}</td>
    <td>{{item.PilgrimID}}</td>
    <td>{{item.GroupName}}</td>
    <td>{{item.PassportNo}}</td>                      
    <td>{{item.Gender}}</td>
    <td>{{item.SubAgentName}}</td>  

enter image description here

Upvotes: 1

Views: 64

Answers (3)

georgeawg
georgeawg

Reputation: 48968

Use the ng-change directive to specify an update function:

<div>Input Start
  <input ng-model="inputStart" ng-change="updateSelections(inputStart,inputEnd)" />
</div>
<div>Input End
  <input ng-model="inputEnd" ng-change="updateSelections(inputStart,inputEnd)" />
</div>

Then update the selections:

$scope.updateSelections = function(iStart, iEnd) {
    $scope.MyList.forEach((x,index)=>item.checked = (iStart<=index && index<=iEnd));
};

Upvotes: 1

Hitesh Kansagara
Hitesh Kansagara

Reputation: 3526

you can do it by adding one property like ItemIndex in your ItemList model, and by putting input box with display none you can get index value in ItemList and can do what you want from javascript side,

<td><input type="text" style="display:none;" ng-model="item.ItemIndex"
           ng-value="$index"/>{{$index}}
</td>

Upvotes: 0

Vamsi
Vamsi

Reputation: 9780

just push the selected values in an array , selectedItemIndexes like ng-checked="selectedItemIndexes.includes($index)"

https://stackblitz.com/edit/angularjs-snavdn

Upvotes: 0

Related Questions