在角度组件中对角度摘要内的jquery事件作出响应

在角度组件中对角度摘要内的jquery事件作出响应

问题描述:

我正试图使这个工作在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的事件角消化内触发?

对任何可能受益的人......我当时很愚蠢。

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

$ q的选择在这里是随机的。它创造了永不被使用的承诺。它应该是$ scope.apply。 – estus

+0

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

+0

它的工作原理是$ q创建一个摘要,但$ q的用法在这里是错误的。有一个错字。它是$ scope。$ apply,而不是$ scope.apply。 – estus