Display a json object into an ionic list grouping by an item (ionic2)

How could i display a json object into an ionic list grouping by an item ( villearrive in my case ):i would like that items will be grouping by ( villearrive) , the actual problem that , for example villearrive “A” is repeated in the result ( it must be appear Only once , below is my json object :

the json object is the result of a web service ; here is the fucntion that returns the result :`RetournerdVoituresEnstation(){

this.voitureservice.getDetailsVilleArrive().subscribe(response => {
this.itemsFile =response.FileS;


and that is the html

<ion-item-group *ngFor="let pr of itemsFile">

<ion-item-sliding >

<ion-item class="item-checkbox-right">
<ion-thumbnail item-left>
<img src="assets/icon/louage.png">
<ion-item-divider color="danger" >{{pr.villearrive}} </ion-item-divider>

I would work backwards from the template. Write the template in a way that makes sense, such as something like this:

<ng-template ngFor let-dest [ngForOf]="dests">
<ion-item *ngFor="let car of dest.cars">

And then massage the data to match what is easy for the template to display:

dests = [];

http.get(url).subscribe((rsp) => {
  let carsByDest = {};
  let raw = rsp.json().FileS;
  raw.forEach((car) => {
    if (!carsByDest[car.villearrive]) {
      carsByDest[car.villearrive] = [];
  for (let dest in carsByDest) {
    dests.push({villearrive: dest, cars: carsByDest[dest]});

yes like rapropos said, and if you’re calling it from and external data source, map it, like

FileS.map.json (output)…
console.log (this.FileS);

// should give you the output

Then you reformulate it in object aka

in constructor Files = any [];

then in view template html model

button click(myData)

and finally in .ts controller file

if this.data ==! undefined (i use it tons this days to precontrol empty forms :p)

// do something


No. Bad. Don’t use any. Don’t recommend that people use any.

It is supposed to be an internal function, of course if your app use anonymous login, sure make it something more secure.

It’s not about security, it’s about readability and avoiding bugs. If you force yourself to provide actual types for everything in your app, you have built yourself some valuable documentation for free, and the build system and IDE autocompletion will guard against typos.

And rapropros I don’t recommend to use any, i know it’s a perfomance loss, just to explain simply i use it.

How to explain it, in my app design everything is already on each key, so i have no worry about who or which can write in firebase.

and I totally agree i should not put anything on : any; was just to explain it simply.

Well done :wink: thanks a lot

glad it helped you, like rapropros said, secure it later, with data types that are not “any” :slight_smile: It can cleary become a security issue and a performance issue, it was just to show you.

1 Like

thanks, you saved my day. :hugs::hugs::hugs: