Parameters and variables between components [Ionic + Firebase]

0

I have a seemingly simple question.

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

  • OneofthechildswithinformationthatIcallisthe{{brewery.reference}}whichgivesmeadifferentvalueforeachitem.Forexample,inthenodethatownsthebreweryHotRod,thevalueis"hotrod".

  • That said, I would like that by clicking the 'see menu' button, I would go to the 'brewery-inside.html' page where, through a passed parameter, I pull the data from the childs relative to the knot of that specific brewery.
    -

asked by anonymous 27.06.2017 / 23:28

1 answer

0

You can pass the whole object as a parameter in your function. On your brewery.html page I advise you to change the name you use in the * ngFor because you are using "brewery of brewery", this may conflict even for you to identify if you are using the loop brewery or brewery or the array of objects. It gets better:

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

This way you can understand that when you use "brewery" in the plural, you are using the loop object, which corresponds to only one brewery and its parameters and when using "brewery" is the array with all breweries. In this case in its function ionViewDidLoad would have to change the "cervajaria" array to "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 entire "brewery" object to your next page. simply change your navigate () function

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

In the file cervejarias.ts you should change the function too:

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

In your brewery-inside.js you will receive in navParams.get ("ParameterReferenciaReferencia") you will already have the object with all the data of the brewery.

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

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

    
30.06.2017 / 14:50