使用angular的页面滚动事件

时间:2017-09-21 12:08:36

标签: javascript angularjs angularjs-directive scroll javascript-events

我想在angular指令中绑定页面滚动事件。我正在尝试以下代码段。但似乎事件不会被解雇:

angular.element($window).bind("scroll", function(e) {
    console.log('page scrolled');
});

我需要帮助,如何实现这个?

1 个答案:

答案 0 :(得分:0)

您可以为浏览器$window注入$document包装,而不是window.document,而不是$document.bind('scroll', function(event) { console.log('page scrolled'); }); (请参阅doc)并使用

const that = this
that.showDiv = true
that.$nextTick(function () {
  that.getWindowWidth()
})