Array of object not received after page navigation


#1

i am sending an array as a parameter during page navigation

listA=[ { id:‘1’,name: ‘jaggu’ },{ id : 2, name: ‘pappu’ } ];

and receiving it as

export class Images{

public firstParam;
public secondParam;

constructor(public platform:Platform,public navParams :NavParams){
    this.platform=platform;
    this.navParams=navParams;
    this.firstParam=navParams.get("listA");
}

}

and using it as:

 <ion-slides style="background:white;">
 <ion-slide *ngFor="#object1 of firstParam">
 <img src="{{objec1.name}}" />
 </ion-slide>
 </ion-slides>

#2

How are you sending it?

it should be something like this

let listA=[ { id:'1',name: 'jaggu' },{ id : 2, name: 'pappu' } ];

this.nav.push(Images, {
    listA: listA
});

and then you can retrieve it like this

constructor(private navParams :NavParams){
    this.firstParam = navParams.get("listA");
}

#3

Unrelated, but both the declarations and assignments in your constructor are redundant. TypeScript will automatically desugar:

constructor(public platform:Platform, public navParams:NavParams) {
}

…into:

public platform:Platform;
public navParams:NavParams;

constructor(platform:Platform, navParams:NavParams) {
  this.platform = platform;
  this.navParams = navParams;
}

Works for private members as well. I wish this was more aggressively documented for newcomers to the language; I didn’t know about it for several months.