Ng-repeat empty row


#1

Hi,

I’m actually trying to get a list with a JSON file.
My JSON is like :

-Host
–Service 1
–Service 8
-Host3
–Service 7

And in my view i’ve this:

<ion-item ng-repeat="servIn in servInconnu" class="message">						
	<h3 class="message title">{{servIn.name}}</h3>
	<p>Services :</p>
	<ion-list>
		<ion-item ng-repeat="serv in servIn" class="message">
			<h4 class="title">{{serv.description}}</h4>
			<p>{{serv.output}}</p>
		</ion-item>
	</ion-list>
</ion-item>

But when i launch this i’ve two empty row…

In my JSON i didn’t have any empty array…

If anyone know how to fix this?

Thanks!


#2

A CodePen with your code may help, but maybe you have some items without subitems. In that case you should hide the second ion-list with ng-if.


#3

Can i say to my list, if the item is empty don’t show him?


#4

ng-repeat require an array,Are you sure your servIn is an array ?


#5

Yes, this is a matter of AngularJS:

e.g.

<ion-list ng-if="servIn.length">

You can also use ng-show, ng-hide…


#6

In my service i get a JSON file i’ve to change the format?

@romeoalex
When i do this my list is empty :frowning:


#7

definitely yes :sunglasses:


#8

JSON is a object , can’t be put it in ng-repeat :smile:


#9

Arf… But why thats works for some row?


#10

You can console.info output in console of browser if you don’t sure to much


#11

Maybe you set the wrong controller or wrong scope :blush:


#12

I’ve test this on what my service return:

if(angular.isArray(data)) {
    console.log('IS ARRAY');
}

And in the console i can see the message.

So i think i can use JSON with ng-repeat no? :hushed:


#13

nop,if you can see the message means your data is not empty,but not means you can use it in ng-repeat


#14

When i receive my JSON he’s like this:

[
    {
        "Host": {
            "id": "15494",
            "name": "Test 8002",
            "Serv": [
                {
                    "description": "rehrhtrhtrj",
                    "last_check": "1418910455"					
                },
                {
                    "description": "tyktkykyk",
                    "last_check": "1429604080",
                }
            ]
        }
    }
]

What i’ve to do for using this in ng-repeat? :persevere:


#15

Don’t worry, You can try this “JSON[0].Host.Serv[index].description” , hope this will work… :smile:


#16

That doesn’t work, how can i convert the JSON for use the ng-repeat?


#17

sorry,my bad , you can try this

      var JSON = [
{
    "Host": {
        "id": "15494",
        "name": "Test 8002",
        "Serv": [
            {
                "description": "rehrhtrhtrj",
                "last_check": "1418910455"                  
            },
            {
                "description": "tyktkykyk",
                "last_check": "1429604080",
            }
        ]
    }
}

]
console.info(JSON[0].Host.Serv[0].description);
so you can use ng-repeat like this item in JSON[0].Host.Serv


#18

YEEAAAAHHHHH :heart_eyes:
Thank you that work!! :blush: