2017-04-19 35 views
1

jscery関数内でtypescriptを呼び出すことができるかどうかわかりません。それが可能ならば、それを行う正しい方法は何ですか?jscery関数内でtypescript関数を呼び出す方法は?

この私のcomponent.ts

getCalendar(){ 
    calendarOptions:Object = { 
    height: 'parent', 
    fixedWeekCount : false, 
    defaultDate: '2017-03-01', 
    editable: true, 
    eventLimit: true, // allow "more" link when too many 

dayclick機能

dayClick: function(date, jsEvent, view) { 
     this.addModal(); **this function is not working** 

     //console.log(jsEvent); 
     // alert('Clicked on: ' + date.format()); 
     // alert('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY); 
     // alert('Current view: ' + view.name); 
     }, 

    success: function(doc) { 
     var events = []; 
     $(doc).find('event').each(function() { 
      events.push({ 
       title: $(this).attr('title'), 
       start: $(this).attr('start') // will be parsed 
      }); 
     }); 
    }, 

    eventAllow: function(dropLocation, draggedEvent) { 
     if (draggedEvent.id === '999') { 
     return dropLocation.isAfter('2017-03-22'); // a boolean 
     } 
     else { 
     return true; 
     } 
    } 
    }; 

    ngOnInit() { 
     this.getTotalEmployee(); 
     this.getComputeAbsent(); 
     this.getTotalAttendance(); 
     // this.showEvent(); 
     this.calendarOptions['events'] = this.events; 

    } 



    public catchError(error: any) { 
     let response_body = error._body; 
      let response_status = error.status; 

      if(response_status == 500){ 
      this.error_title = 'Error 500'; 
      this.error_message = 'The given data failed to pass validation.'; 
      } else if(response_status == 200) { 
      this.error_title = ''; 
      this.error_message = ''; 
      } 

     } 

    showEvent(){ 
     this._event_service.getEventList() 
     .subscribe(
      data => { 
      this.events = Array.from(data); 
      this.calendarOptions['events'] = this.events; 
      console.log(this.calendarOptions['events']); 

      }, 
      err => this.catchError(err) 

    ); 
     } 


    getEvents() { 
     this._event_service.getEvents().subscribe(
     data => { 
      this.eventsList = Array.from(data); 
      this.calendarOptions['events'] = this.eventsList; 

     }, 
     err =>{} 
    ); 
    } 

これは、上記のjqueryの関数で呼び出そうとイム私のモーダル機能です

addModal() { 
    let disposable = this.modalService.addDialog(EventComponent, { 
      title:'Add Event' 
      }).subscribe((isConfirmed)=>{ 
     }); 
    } 
    getTotalAttendance() { 
     let pre; 
     this._attend_service.getTotalPresent().subscribe(
     data => { 
      pre = Array.from(data); 
      this.present = pre[0].total_present; 

     }, 
     err =>{} 
    ); 
    } 

    getTotalEmployee() { 
     let totalEmp; 
     let filter = "Active"; 
     this._attend_service.getTotalEmp(filter).subscribe(
     data => { 
      totalEmp = data; // fetced record 
      this.total_emp = totalEmp[0].total_employee; 

     }, 
     err =>{} 
    ); 
    } 

    getComputeAbsent(){ 
     let employee = parseInt(this.employee); 
     let attendance = parseInt(this.attendance); 

      this.totalAbsent = employee - attendance; 


     } 

答えて

2

あなたは必要としない場合は同封this

あなたは矢印の機能を使用することができます

dayClick: (date, jsEvent, view)=> { 
      this.addModal(); 
      } 

をそれとも、変数に外thisを保存し、後でそれを使用することができます

var self = this; // store here 
dayClick: function(date, jsEvent, view) { 
      self.addModal(); // use here 
      } 

編集:

getCalendar(){ 
    var self = this; // ****** 
    calendarOptions:Object = { 
    height: 'parent', 
    fixedWeekCount : false, 
    defaultDate: '2017-03-01', 
    editable: true, 
    eventLimit: true, // allow "more" link when too many 
    dayClick: function(date, jsEvent, view) { 
     self.addModal(); // ********* 
     }, 

    success: function(doc) { 
     var events = []; 
     $(doc).find('event').each(function() { 
      events.push({ 
       title: $(this).attr('title'), 
       start: $(this).attr('start') // will be parsed 
      }); 
     }); 
    }, 

    eventAllow: function(dropLocation, draggedEvent) { 
     if (draggedEvent.id === '999') { 
     return dropLocation.isAfter('2017-03-22'); // a boolean 
     } 
     else { 
     return true; 
     } 
    } 
    }; 
+0

@AlyssaAndreaあなたは全体 'dayClick'機能を共有することができれば、私はより正確には私の答えを編集します。どの角度の方法のように? – echonax

+0

私はこれでhekpできることを望んでいます –

+0

@AlyssaAndrea問題はありませんが、 'dayClick'を取り巻くコードの外側のメソッドを共有できますか? – echonax

関連する問題