Create public variable and use it as Button-caption


#1

Hi,

I am looking for a way to create a variable that I can access from a different pages. I want to create it at one page and use it as button-caption on another page.

This is the first page. In this .ts I want to create the variable:

export class SettingsPage {

  constructor(public navCtrl: NavController, public navParams: NavParams) {}
  
        getValues(){
		var goal:number = 5;
}

}

And this is the second page where I want to use it as label (.html):

<ion-content>
<button ion-button large >variable {{goal}}</button>
</ion-content>

If you have any suggestions how to do this, in the best case with some code, I would be very thankfully.

Greetings,

Robert


#2

I think you would really benefit from going through the Tour of Heroes. It would have answered your last couple of questions, it will answer this one, and it will answer the next ten or so as well.


#3

See: https://angular.io/guide/component-interaction