AngularJS - Unbind $window of an event from specific directive

前端 未结 4 1049
甜味超标
甜味超标 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:17

    bind:

    $window.onscroll = function() {
    //your code
    };
    

    unbind:

    $scope.$on('$destroy', function () {
         $window.onscroll = undefined;
    });
    

提交回复
热议问题