Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

my pages uses lots of ng-repeat to generate table rows. If there is no data in an json array, there would be an empty table. I'm trying to skip generating table rather than an generate an empty one.

To do that, I need to check if the array length is 0. In js I can get array length using its length property:

$scope.data.errors.length === 0

But I can't use it in angular watcher, the following has no output

{{data.errors.length}}

And data.errors.length === 0gives false.

So is there a way to get json array length in angular?

share|improve this question
    
Can you show more of the code? –  TGH Oct 28 '14 at 2:19
    
have you tried just using ng-if="data.errors" in the tables parent –  Dylan Oct 28 '14 at 2:20
    
Have you tried $scope.data.length? –  JLewkovich Oct 28 '14 at 2:28
    
you want to display table of data or data.error –  entre Oct 28 '14 at 3:40
    
ng-show="data.error.length > 0" works. Thanks and sorry for asking such a simple question... –  DeepNightTwo Oct 28 '14 at 3:59

1 Answer 1

up vote 1 down vote accepted

You can use ng-show Ex.

<div ng-show=data.errors> your html </div>

Or you can use ng-repeat following code will execute if there is an error

   <div ng-repeat="error in data.errors"></div> 

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.