Push multiple elements


#1

hi, I wan’t to push ‘medication’ and ‘kg’ to MedPage. I’ve tried it like this but this give’s error:"cannot create property ‘direction’ on number ‘20’ (20 = value for ‘kg’)

import { Component,Input,OnInit } from ‘@angular/core’;
import { NavController, NavParams, ModalController } from ‘ionic-angular’;
import { lftgewPage} from ‘…/lftgew/lftgew’;
import { Medicatie } from ‘…/…/data/medicatie.interface’;
import medicaties from ‘…/…/data/medicatielijst’;
import { MedPage } from ‘…/med/med’;

@Component({
selector: ‘page-medgew’,
templateUrl: ‘medgew.html’,

})
export class MedgewPage implements OnInit {

public kg;
medicatieverzameling: any;
medPage = MedPage;

ngOnInit(){
this.medicatieverzameling = medicaties;
}

constructor(public navCtrl: NavController, public navParams: NavParams,private modalCtrl: ModalController ) {

}

ionViewDidLoad() {
this.kg = this.navParams.get (‘gewicht’);
}

gotoMedPage(medicatie){
this.kg = this.navParams.get (‘gewicht’);
let kg= this.kg;

this.navCtrl.push(MedPage,medicatie,kg);

}
gotolftgewPage(){
let modal=this.modalCtrl.create(lftgewPage);
modal.present();
}
}


#2
this.navCtrl.push(MedPage, {
    medicatie: medicatie,
    kg: kg
});

Only the second parameter is for data you want to forward, make it an object.


#3

thanks for the quick response. I’ve tried this, but in this case I only get the ‘kg’ pushed.


#4

How are you retrieving the data on MedPage? Make sure that medicatie actually has data in it

console.log(medicatie, kg); /* Do both log the expected data to the console? */
this.navCtrl.push(MedPage, {
    medicatie: medicatie,
    kg: kg
});


...


// In MedPage
constructor(...) {
    console.log(this.navParams.data); /* Is the data still there? */
}

#5

when I push only medicatie this will work. When I push {medicatie} it won’t. push (MedPage, {kg}), does work.

medicatielijst.ts:

export default
[

{merknaam: “Adrenaline”,
generisch: “epinefrine”,
dosis:“0,01mg/kg”,
vorm:“IV”,
doel:“CPR”,
info:“1mg/10cc NaCL 0,9% → 0,1cc = 10µg”,
formule: 0.01},

{merknaam: “Adrenaline”,
generisch: “epinefrine”,
dosis:“0,4mg/kg aerosol ; 0,01mg/kg IM”,
vorm:“aerosol, IM”,
doel:“anaphylaxis”},

{merknaam: “Cordarone”,
generisch: “amiodarone”,
dosis:“5mg/kg”,
vorm:“IV”},

{merknaam: “Paracetamol”,
generisch: “”,
dosis:“15mg/kg”,
vorm:“IV/po”},

{merknaam: “ibuprofen”,
generisch: “”,
dosis:“10mg/kg”,
vorm:“po/suppo”},

med.ts:

import { Component } from ‘@angular/core’;
import { ViewController, NavParams } from ‘ionic-angular’;
import { MedgewPage } from ‘…/medgew/medgew’;
/*
Generated class for the Med page.

See http://ionicframework.com/docs/v2/components/#navigation for more info on
Ionic pages and navigation.
*/
@Component({
selector: ‘page-med’,
templateUrl: ‘med.html’
})
export class MedPage {
merknaam: string;
generisch: string;
vorm: string;
dosis: string;
kg: number;
doel: string;
info: string;
formule: number;
resultaat: number;

constructor(private viewCtrl: ViewController, private navParams: NavParams, ) {

}

ionViewDidLoad() {
this.merknaam = this.navParams.get(‘merknaam’);
this.generisch = this.navParams.get(‘generisch’);
this.dosis = this.navParams.get(‘dosis’);
this.vorm = this.navParams.get(‘vorm’);
this.kg = this.navParams.get(‘kg’);
this.doel = this.navParams.get(‘doel’);
this.info = this.navParams.get(‘info’);
this.formule= this.navParams.get(‘formule’);
}
Resultaat(){
this.formule*this.kg==this.resultaat;
return
}
onClose() {
this.viewCtrl.dismiss();
}

}

med.html

  <h1>{{merknaam}}</h1>
  <h5>{{generisch}}</h5>
  <h3 >{{doel}}</h3>
  {{kg}}kg
</ion-title>

{{merknaam}}

{{generisch}}

{{dosis}}

{{vorm}}

{{info}}

{{resultaat}} back

#6

med.html:

  <h1>{{merknaam}}</h1>
  <h5>{{generisch}}</h5>
  <h3 >{{doel}}</h3>
  {{kg}}kg
</ion-title>

{{merknaam}}

{{generisch}}

{{dosis}}

{{vorm}}

{{info}}

{{resultaat}} back

#7

Please try formatting your code, it is very hard to read.

```
function codeGoesHere() { }
```

I’m not sure you’re actually doing what I’m saying. Send both exactly like this

this.navCtrl.push(MedPage, {
    medicatie: medicatie,
    kg: kg
});

If you want to access the data on MedPage, do it exactly like this

console.log(this.navParams.data.medicatie);
console.log(this.navParams.data.kg);

// or

console.log(this.navParams.get("medicatie"));
console.log(this.navParams.get("kg"));

If this does not work, send me the code you have for where you are trying to access the data and the code for your nav push. Nothing else.