Parameters and variables between components [Ionic + Firebase]

Asked

Viewed 1,896 times

1

I’m with a seemingly simple doubt.

  • I have a project connected to firebase. In this specific case, I have a *ngFor list of breweries on the "breweries.html" page where I pull all the main JSON nodes /brewery.
    cervejarias.html
    cervejarias.ts

  • One of the Childs with information I call is {{brewery.referencia}} which gives me a different value for each item. For example, in the knot that owns the Hot Rod brewery, the value is "hotrod".

  • Having said that, I would like, when clicking the 'view menu' button, to direct me to the 'brewery-Inside.html' page where, through a parameter passed, I pull the Childs data relative to the node of that specific brewery.
    cervejarias-inside.html
    cervejarias-inside.ts
    JSON exemplo com os dados
    inserir a descrição da imagem aquiinserir a descrição da imagem aqui

1 answer

0

You can pass the whole object as a parameter in its function. On your page html breweries. I advise changing the name you use in *ngFor because you are using "brewery of brewery", this can give conflict even to you identify whether you are using the brewery of the loop or brewery the array of objects. looks better:

<ion-card *ngFor="let cerveja of cervejarias | async">

This way we understand that when you use "brewery", in plural, you are using the object of the loop, which corresponds to only one brewery and its parameters and when you use "breweries" is the array with all breweries. In this case in its function ionViewDidLoad would have to exchange the array "cervajaria" for "breweries".

From what I saw of your code you are bringing all the information of the brewery in this array, so you can pass the whole "brewery" object to your next page. just change your navigate function()

<button ion-button icon-left clear item-end (click)="navigate(cervejaria)">

In the brewery.ts file should change the function also:

navigate(objSelecionado){
    this.navCtrl.push(CervejariaInside, {
        parametroReferenciaEnviado: objSelecionado
    })
}

In your brewery-Inside.js you will receive in navParams.get("parametroReferenciaciaEnviado") you will already have the object with all the data from the brewery.

this.cervejaria = navParams.get("parametroReferenciaEnviado")

If you need to use the reference just use this.cervejaria.referencia

Browser other questions tagged

You are not signed in. Login or sign up in order to post.