Goran
Goran

Reputation: 3

Array of objects in AngularJs

$scope.items = [];
$scope.items.push(items);
<div ng-repeat="item in items">
    <div ng-repeat="(key, value) in item">
        {{value.ItemId}}
    </div>
</div>

How to avoid nested ng-repeat when iterating through an array of objects/arrays?

Upvotes: 0

Views: 145

Answers (2)

link
link

Reputation: 1676

Why don't you use $resource to get your items from the server?

$resource returns a promise that can be assigned to your scope and will be populated with the data by Angular automatically.

var Items = $resource('/yourUrl');

$resource docs

After you implement your ajax call as a resource, you can simply do $scope.items = Items.query().

Upvotes: 0

Idkt
Idkt

Reputation: 2996

You shouldn't push one array into another, use angular.extend

$scope.items = [];
angular.extend($scope.items, items);


<div ng-repeat="(key, item) in items">
    {{item.ItemId}}
</div>

Upvotes: 1

Related Questions