2017-07-11 71 views
0

我們正在使用ap-angular2-fullcalendar進行事件列表。 關於回調(點擊事件)函數,我們想要更新一個變量值。如何從jquery/javascript更改角度4的變量值

this.calendarOptions = { 
     height: 450, 
     fixedWeekCount: false, 
     defaultDate: today, 
     editable: false, 
     eventLimit: true, 
     header: { 
     left: 'month agendaWeek agendaDay', 
     center: 'title', 
     right: 'today prev,next' 
     }, 
     events: [], 
     eventClick: this.calEventOnClick 
    }; 

calEventOnClick:

calEventOnClick(appObj, jsEvent, view){ 
    //Following are the angular properties which values we want to update 
    this.sessionId = appObj.id; 
    this.showAppoint = appObj; 
    this.isAppointmentsBox = false; // not working 
    this.isAppointmentDetails =true; // not working 
} 

回答

0

在使用回調,記住要經常檢查上下文;在這裏你應該使用bind(this)來保持上下文。

this.calendarOptions = { 
    ... 
    eventClick: this.calEventOnClick.bind(this)  // <----- bind context to callback here 
}; 
+0

非常感謝! –