0

I have a JSON string passed to angular. One of the array fields has another array, called products. How can I do an angular repeat on those items?

When I just use {{item.products}}, the products print out, but not in a repeat fashion. How can I iterate those products as well?

Here my angular:

function CashTransController($scope, $http)  {

        $scope.items = {[$data]}    
        $scope.mySortFunction = function(item) {
            if(isNaN(item[$scope.sortExpression]))
                return item[$scope.sortExpression];
            return parseInt(item[$scope.sortExpression]);
        }


        $scope.refreshSessionList = function(){


            $http({
                method: 'POST',
                url: 'browser.php?conference_year='+$scope.conference_year,
                headers:{'Content-type' : 'application/x-www-form-urlencoded; charset=UTF-8'}
                });   
        }

}

<tr ng-show="search" ng-repeat="item in items | filter:search">
   <td>{{item.firstname}} {{item.lastname}}</td>
   <td>|</td>
   <td valign="top">{{item.redemption_code}}</td>
   <td>|</td>
   <td>${{item.amount}}</td>    
   <td>|</td>
    <td>{{item.creation_date}}</td>  
    <td>|</td>
    <td>{{item.products}}</td>

    <td><a href="redeem_cash_transaction.php?id={{item.id}}" onClick="return confirm('Are you sure? This action cannot be undone!');">Complete Transaction</a><td>  

</tr>

1 Answer 1

1

When you go to item.products, you can also do another ng-repeat there, e.g.

<td><span ng-repeat="product in item.products">{{product}}</span></td>
Sign up to request clarification or add additional context in comments.

1 Comment

also, I moved the original repeat to the table level, so I don't miss the scope of item.products.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.