maskers maskers - 4 months ago 7
AngularJS Question

Why is my ng-repeat is only displaying first result?

I have this array of an array of objects that I am pushing onto from results I pass from a modal;

"id": 4,
"name": "THROTTLE TUBE",
"partno": "104-",
"oemnumber": "46019 038",
"stock": 19,
"price": "28"
"id": 28,
"name": "TACHOMETER, CUP",
"partno": "128-",
"oemnumber": "25012 011",
"stock": 7,
"price": "46"

I am getting this from the following;

$scope.woParts = [];

//later in my modal code - which is where the double [] is coming from
modalInstance.result.then(function(woParts) {

I am then using this ng-repeat in my view;

<div ng-repeat="woPart in woParts">
<div class="col-md-4">
@{{ woPart[$index].name }}
<div class="col-md-2">
@{{ woPart[$index].oemnumber }}
<div class="col-md-2">
@{{ woPart[$index].price | currency}}
<div class="col-md-2">
<input type="number"

This only displays the first result in the array. Why is that?


I don't think you should push woParts into another object. Just save it to the scope: $scope.woParts = woParts;. Then there is no need to use $index in the ngRepeat, just use regular dot notation:

Or if you have to push woParts into another array, then you can change the ngRepeat expression to woPart in woParts[0].