I'm having an issue with binding and displaying the value of an array. When I assign the value using the scope variable like this:
$scope.StockList = obj.data
Everything works fine. However, when I try to push the value into the array like this
$scope.StockList.push(obj.data);
It doesn't work as expected.
I am facing a problem with ng-repeat and scope variable. Can someone help me out? Here is my code snippet.
$scope.StockList = [];
$scope.IsVisible = false;
var Stocks = [];
function GetStockEntries(loid, pid) {
var data = { LocationId: loid, ProductId: pid }
return $http.post(serviceURL + "/GetLocationStockEntries", data).then(
function success(data, status, headers, config) {
var obj = JSON.parse(data.data.d)
//working fine in case single array
//$scope.StockList = obj.data
$scope.StockList.push(obj.data);
},
function error(data, status, headers, config) {
return data
}
)
}
$scope.StockListing = function (item) {
debugger
$scope.IsVisible = !$scope.IsVisible
console.log($scope.StockList)
}
Here is the ng-repeat code snippet
<table cellpadding="5" cellspacing="0" class="stocktransferdiv">
<tr>
<td colspan="4">
<table cellpadding="5" cellspacing="0" data-ng-repeat="stockItem in StockList" data-ng-show = "IsVisible" data-ng-cloak width="100%">
<tr style="border-bottom: 1px solid #ddd; padding-bottom: 5px; margin-bottom: 5px; float: left;">
<td>
<input type="radio" name="groupName" data-ng-value="true" data-ng-model="stockItem.selected" data-ng-change="onTaskSelect(stockItem)" />
</td>
<td>
<input type="text" data-ng-model="stockItem.UserInventoryItemID" disabled="" readonly="" style="border: none; background-color: white;">
</td>
<td>
<input type="text" data-ng-model="stockItem.LotNumber" disabled="" readonly="">
</td>
<td>
<span>{{stockItem.QuantityOnHand}}</span>
<span>{{stockItem.UnitName}}</span>
</td>
<td>
<input type="text" data-ng-model="stockItem.EnteredQuantity" >
</td>
<td>
<input type="text" data-ng-model="stockItem.Description" disabled="" readonly="">
</td>
</tr>
</table>
</td>
</tr>
</table>
And here is the output of that json