Kreepz
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!
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.
Kreepz
3
Can i say to my list, if the item is empty don’t show him?
ng-repeat require an array,Are you sure your servIn is an array ?
Yes, this is a matter of AngularJS:
e.g.
<ion-list ng-if="servIn.length">
You can also use ng-show, ng-hide…
Kreepz
6
In my service i get a JSON file i’ve to change the format?
@romeoalex
When i do this my list is empty
JSON is a object , can’t be put it in ng-repeat
1 Like
Kreepz
9
Arf… But why thats works for some row?
You can console.info output in console of browser if you don’t sure to much
Maybe you set the wrong controller or wrong scope
Kreepz
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?
nop,if you can see the message means your data is not empty,but not means you can use it in ng-repeat
Kreepz
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?
Don’t worry, You can try this “JSON[0].Host.Serv[index].description” , hope this will work…
Kreepz
16
That doesn’t work, how can i convert the JSON for use the ng-repeat?
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
1 Like
Kreepz
18
YEEAAAAHHHHH
Thank you that work!!