Skip to content

Angular中如何监听window滚动事件? #6

@kungfuboy

Description

@kungfuboy

你好,我需要做一个滚动无限加载的组件,那么必然要用到滚动监听,我自己折腾了一会,似乎需要用到@HostListener这个东西,很陌生,书里貌似没写(也可能写了,但我水平还不够,尚未啃完整本书)

    @HostListener('window:scroll', ['$event'])
    onScroll(event: any) {
        console.log("scrolling");
    }

已经从@angular/core导入,但是并没有起作用,也没有报错,我试过把事件改成click,其他没变,是可以的监听到click事件的,唯独监听不到滚动。
image

请问问题出在哪呢?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions