Why does undefined tell me when doing a variable?

0

Greetings I have a variable which I declare like this: public clickNotification: boolean = false ;. But when clicking, you must change from false to true and when I do the console.log (this.clickNotification). In the console.log it shows undefined.

public clickNotificacion:boolean=false;
constructor(public navCtrl: NavController){
LocalNotifications.on("click", function (notification) {
  console.info("Despues del click"+this.clickNotificacion);
  console.log(notification.id);
});
}

ionic info: Your system information:

Cordova CLI: 6.4.0 Ionic Framework Version: 2.0.0-rc.2 Ionic CLI Version: 2.1.8 Ionic App Lib Version: 2.1.4 Ionic App Scripts Version: 0.0.43 ios-deploy version: Not installed ios-sim version: Not installed OS: Linux 4.8 Node Version: v6.5.0 Xcode version: Not installed

    
asked by Wuilmer Medrano 28.01.2017 в 06:16
source

1 answer

1

Do not use on () and less inside the constructor. Just create the function outside the constructor:

public clickNotificacion: boolean = false;

constructor(public navCtrl: NavController) {}

changeNotification() {
    this.clickNotificacion = !this.clickNotificacion;
});

And in the template you refer to it:

<button ion-item (click)="changeNotification()">
  <ion-icon item-left name="notifications"></ion-icon>
  Notificaciones
</button>
    
answered by 01.02.2017 в 08:00