I'm new to angularjs and I've encountered a pretty annoying problem. In my app I'm using a factory that holds all the functions, and let the controllers use them. I created a function that's returning an array and printing it on the web page, but when the returned array contains only 1 variable, it prints sort of an empty list. it works fine when there's more than 1 variable in the array. console.log shows that the array contains the variable, but it won't print it on my list.
I'm also using bootstrap if that matters.
I hope I explained my problem properly. Thanks for the help!
Factory:
function getArray(var){
return $http.get(restURL+var).then(
function(response){
return response.data.coupon;
}
);
}
Controller:
$scope.getArrayFunction = function(){
appServicesProvider.getArray($scope.var).then(function(coupons){
$scope.arrayVar = coupons;
})
}
HTML:
<div id="getArrayDiv">
<table class="table table-hover">
<thead>
<tr>
<th>#</th>
<th> Title</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="coupon in arrayVar">
<td>{{coupon.id}}</td>
<td>{{coupon.title}}</td>
</tr>
</tbody>
</table>
<input type="text" class="form-control" placeholder="Enter Type" ng-model="var" required="true">
<button class="btn btn-success" ng-click="getArrayFunction()" >Get Array</button>
</div> <!-- /getArrayDiv -->
couponsis a object and not array