Pass variable through MyApp to pages


#1

Hello,
I’m using today Ionic 2 for the first time and I’m new to A2 ( I always developed with 1.x ).

I’m trying to pass a variable “countChat” from the class MyApp to a page, but without success.

/app/app.js

class MyApp {
    
  static get parameters() {
    return [[IonicApp], [Platform], [MenuController]];
  }

  constructor(app, platform, menu) {
    // set up our app
   [...]

    // set our app's pages
   [...]

    // make HelloIonicPage the root (or first) page
    [...]
    this.countChat = 3;

/app/pages/[page-name]/[page-name].html

<div>{{ countChat }}</div>

This is the code, but in the page nothing is showed.

Thanks!


#2

is better you put all the Chat vars and functions in a provider, take a look in the conferece app how its works.


#3

Thanks. Now I can see the OOP logic of TypeScript :slight_smile: