2017-08-06 57 views
0

我正試圖使這個工作在angularJS中的$ onInit函數中。在角度組件中對角度摘要內的jquery事件作出響應

popup() { 
    this.$log.log("popup clicked..."); 
} 

constructor(
    public $log: ILogService, 
    public $timeout: ITimeoutService, 
    public $q: IQService, 
    public $element: any) { 

    // i have tried this 
    $element.on("click custom:event", $q.when(() => this.popup())); 

    // and this. 
    $element.on("click custom:event", $timeout(() => this.popup(), 1000)); 

    // I have also tried the scope (last resort) 
    $element.on("click custom:event", $scope.apply(() => this.popup()); 
} 

在每種情況下的錯誤是:

Uncaught TypeError: ((jQuery.event.special[handleObj.origType] || (intermediate value)).handle || handleObj.handler).apply is not a function at HTMLElement.dispatch at HTMLElement.elemData.handle

有沒有辦法正確地創建這樣的承諾,jQuery的事件角消化內觸發?

回答

0

對任何可能受益的人......我當時很愚蠢。

this.$element.on("click",() => $q(() => this.popup())); 
+0

$ q的選擇在這裏是隨機的。它創造了永不被使用的承諾。它應該是$ scope.apply。 – estus

+0

這很奇怪 - 它的工作原理? – Jim

+0

它的工作原理是$ q創建一個摘要,但$ q的用法在這裏是錯誤的。有一個錯字。它是$ scope。$ apply,而不是$ scope.apply。 – estus