AngularJS - Unbind $window of an event from specific directive

前端 未结 4 1077
甜味超标
甜味超标 2021-01-08 00:12

Inside one of my directives, I use angular.element($window).bind(\'scroll\'). When the directive is destroyed, I then want to unbind it. Normally,

4条回答
  •  爱一瞬间的悲伤
    2021-01-08 00:43

    JQuery's on() supports namespacing events so they can be removed independent of each other.
    (https://api.jquery.com/on/)

    Angular's jqLite however, does not.
    (https://docs.angularjs.org/api/ng/function/angular.element)

    But if you include JQuery before Angular then JQuery will replace jqLite and you should be able to use namespaces. That's possibly not what you wanted to hear, but I'm not aware of any other way.

提交回复
热议问题