Aravinthan K Aravinthan K - 5 months ago 42
jQuery Question

ng-hide and ng-show not working Properly

I want to hide and show depending upon data values. I do not know what's wrong with my code. When I look for the data value by looking at console logs they print " [ ] "

My Controller

$http.get('/bill/billByPatientId/'+patientData.id)
.success(function (data, status, headers, config) {
console.log(data);
$scope.bills = data;
});


My Html Code

ng-hide:

<div class="row" data-ng-hide='bills'>
<div class="alert alert-info">
<strong>No Bills!</strong> There is no history of bill for this
patient
</div>
</div>


ng-show :

<div>
<table data-ng-show='bills' class="table table-hover">
<thead>
<tr>
<th class="col-lg-1 text-center">Bill No</th>
<th class="col-lg-1 text-center">Date</th>
</tr>
</thead>
<tbody class="scrollable">
<tr data-ng-repeat="bill in bills">
<td class="text-center">{{bill.billNo}}</td>
<td class="text-center">{{bill.billDate | date:'dd-MM-yyyy'}}</td>
</tbody>
</table>
</div>


My Problem is showing ng-show contents. Please help.

Answer

This works for me !

Thanks Nano

data-ng-show='bills.length > 0' 

data-ng-hide='bills.length > 0'

or

data-ng-show='bills[0]' 

data-ng-hide='bills[0]'