在Ionic Local Notifications中访问其外部的构造函数内的变量

时间:2017-11-15 19:26:11

标签: angularjs typescript ionic-framework hybrid-mobile-app localnotification

export class HomePage 
{

 constructor(public navCtrl: NavController, public alertCtrl: AlertController, private plt: Platform, public localNotifications: LocalNotifications,) {
     this.plt.ready().then((rdy) => {

       let date = new Date();
       let before_work_notification_time = new Date(date.setHours(7,0,0) )


       this.localNotifications.schedule({
         id:1,
         title: 'Good morning',
         text: 'My morning notification' + before_work_notification_time.getHours(),
         at: before_work_notification_time,
         every: 'day',
         data: { mydata: 'My daily before work notification'}
       });
}
}

我想在“ionViewDidLoad()”中的构造函数之外访问“work_start_notification_time”的值。有可能吗?我试图想出一个我创建的所有通知时间的图表。或者,是否可以使用它的“id”访问我创建的本地通知?

提前致谢, SKR

1 个答案:

答案 0 :(得分:1)

export class HomePage 
{

//outside scope variables
public work_start_notification_time:any ;

 constructor() {
    //assign a value 
this.work_start_notification_time = "somevalue";

}

someMethod()
{
  //access from outside constructor 

console.log(this.work_start_notification_time);
}
}