My issue arises when transferring data from HTML in the following format
Karbohidrat :{{karbohidrat}} <button ion-button (click)="cekHalamanMakanan('karbohidrat')">View carbohydrate foods</button> <br>
Then, I retrieve the karbohidrat using the cekHalamanMakanan function like this
cekHalamanMakanan(value)
{
}
Upon trying to console.log, the correct response is displayed.
Subsequently, I aim to add the value to an array and send the array to the next page using navctrl
gizi: any;
this.gizi= {};
this.gizi = this.navParams.data;
this.karbohidrat=this.gizi.karbohidrat;
this.protein_hewani=this.gizi.protein_hewani;
this.protein_nabati=this.gizi.protein_nabati;
this.lemak=this.gizi.lemak;
this.jenis=this.gizi.value;
When receiving it using navparams
this.makanan = {}
this.makanan = this.navParams.data;
this.variabel = this.makanan.jenis;
However, upon attempting to view it through console.log, "undefined" is displayed..
Below is the complete code snippet:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFireDatabase} from 'angularfire2/database';
import { HalamanmakananPage} from '../halamanmakanan/halamanmakanan'
/**
* Generated class for the RekomendasiPage page.
*
* See http://ionicframework.com/docs/components/#navigation for more info
* on Ionic pages and navigation.
*/
@Component({
selector: 'page-rekomendasi',
templateUrl: 'rekomendasi.html',
})
export class RekomendasiPage {
gizi: any;
karbohidrat: number;
protein_hewani: number;
protein_nabati: number;
lemak: number;
jenis: string;
value: string;
constructor(public navCtrl: NavController, public navParams: NavParams) {
}
ionViewDidLoad() {
console.log('ionViewDidLoad RekomendasiPage');
}
cekHalamanMakanan(value)
{
console.log(value);
this.gizi= {};
this.gizi = this.navParams.data;
this.karbohidrat=this.gizi.karbohidrat;
this.protein_hewani=this.gizi.protein_hewani;
this.protein_nabati=this.gizi.protein_nabati;
this.lemak=this.gizi.lemak;
this.jenis=this.gizi.value;
console.log(this.karbohidrat,this.protein_hewani,this.protein_nabati,this.lemak,this.jenis);
this.navCtrl.push(HalamanmakananPage,this.gizi);
}
}