1

I am trying to call a function for each iteration in ng-repeat, but the function is executing only for the last record.

PFB the code:

Controller:

$http({

         url: _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/GetByTitle('TestList1')/items",
        method:"GET",
        headers:{"Accept":"application/json;odata=verbose"},
        }).then(function success(data)
        {
        $scope.items=data.data.d.results;


        },
        function error(data)
        {

        });



$scope.getQualities=function(level2)
    {
    $scope.oppLevel2=level2.toString();

    $http({

         url: _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/GetByTitle('TestList2')/items?$filter=Level2 eq '"+$scope.oppLevel2+"'",
        method:"GET",
        headers:{"Accept":"application/json;odata=verbose"},
        }).then(function success(data)
        {

            $scope.qualityOpp=data.data.d.results;  


        },
        function error(data)
        {

        });


    };

HTML:

<table>
<tr ng-repeat="item in items">
<td><div class="nonEditable" id="nonEditableQualityOpportunities{{item.ID}}" ng-init="getQualities(item.Level2)"><span ng-repeat="quality in qualityOpp">{{quality.Title}}<br></span></div>
<span class="editable" id="editablePlannedBTSolution2{{item.ID}}">
<input type="text" class="dropDown">
</span>

</td>

</tr>
</table>

1 Answer 1

0

You should change your template as below

<table>
    <tr ng-repeat="item in items">
        <td>
            <div class="nonEditable" id="nonEditableQualityOpportunities{{item.ID}}">
                <span ng-repeat="quality in qualityOpp">{{quality.Title}}<br></span>
                {{ getQualities(item.Level2) }}
            </div>
            <span class="editable" id="editablePlannedBTSolution2{{item.ID}}">
                <input type="text" class="dropDown">
            </span>
        </td>
    </tr>
</table>
1
  • 1
    It is going into an infinite loop
    – Dheeraj
    Commented Oct 24, 2017 at 12:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.