响应 angular 组件中 angular 摘要中的 jquery 事件

respond to jquery event within an angular digest in an angular component

我正在尝试在 angularJS 中的 $onInit 函数上进行这项工作。

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

有没有一种方法可以正确创建承诺,以便在 angular 摘要中触发 jQuery 事件?

对于任何可能受益的人...我是愚蠢的。

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