0

I am trying to use nested ng-repeat. However, the values in the upper ng-repeat will be passed as a parameter in the inner ng-repeat. I am trying to create a function that returns an array So that I can use it in the inner ng-repeat. but it seems not working. how can I achieve this? this is my html

<table class="table table-condensed" id="paytable" ng-repeat="row in employeeInfo">
    <thead>
        <tr>
            <td class="col-sm-3">Employee Info</td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>{{employeeInfo.name}}</td>
            <td>
                <ul ng-repeat="row in employeeLoans(employeeInfo)">
                    <li></li>
                </ul>

            </td>
        </tr>
    </tbody>

</table>

this is the angularJS

// this 
$http.get('/api/PreviewEmployee').success(function (data)
{
    $scope.employee = data;

    $scope.Allowances = Allowance(data);
});

$scope.Allowance = function (data)
{
    var result = [];
    for(var i = 0 ; i < data.length ; i++)
    {
            result.push(data[i]);                 
    }
    console.log(result)
    return result;
}

    

thanks in advance!!!

Ahmet Emre Kilinc
  • 5,489
  • 12
  • 30
  • 42
Lamin L Janneh
  • 75
  • 1
  • 10
  • please provide the sample data for testing – Naga Sai A Jun 09 '16 at 15:54
  • I can see the data obtain from the server with this $scope.employee = data; which is definitely a sample – Lamin L Janneh Jun 09 '16 at 15:57
  • 1
    I think this can help you http://stackoverflow.com/questions/26399783/how-to-properly-execute-a-function-inside-ng-repeat – Isaac Jun 09 '16 at 15:59
  • I was looking at it before but how can I structure my controller to get the values for inner ng-repeat.please I need help Also, I am not using button click to get the information is on page load – Lamin L Janneh Jun 09 '16 at 16:06

1 Answers1

0

I have created code pen with sample data var x = $scope.employee;

              var keys = Object.keys($scope.employee);

              var result = [];
              for (var i = 0; i < keys.length; i++) {
                result.push(x[keys[i]]);
              }

              $scope.Allowances = result;
              console.log($scope.Allowances);});

Codepen URL -http://codepen.io/nagasai/pen/EyPZjQ for reference

Hope this is helpful for you :)

Naga Sai A
  • 10,771
  • 1
  • 21
  • 40
  • the problem is the way I structure my controller I need help to structure the controller from this two dependent request // this should fill the outter NGRepeat $http.get('/api/PreviewEmployee').success(function (data) { $scope.employee = data; }); // this should fill the inner NGRepeat $http.get('/api/PreviewAllowance/' + parentEmpID).success(function (data) { $scope.Allowance = data; }); – Lamin L Janneh Jun 09 '16 at 17:05