Dec*_*r94 5 html infinite-scroll angular
我正在关注本教程,但不确定它是否已过时。
我正在使用@angular/core": "^5.2.0"所以我正在使用这个版本 ngx-infinite-scroll@0.8.3
我已经添加了:
import { InfiniteScrollModule } from 'ngx-infinite-scroll';
并InfiniteScrollModule在 app.module.ts 中导入。
在Search.component.ts我添加了directives: [InfiniteScroll]tp@Component但是当我在“ngx-infinite-scroll”中选择选项卡时它似乎不再存在,我可以看到InfiniteScrollDirective但没有实现它。
我可以让应用程序编译的唯一方法是摆脱directives: [InfiniteScroll]但无限滚动不起作用(它只是一个普通滚动)。
网址:
<div class="search-results"
infiniteScroll
[infiniteScrollDistance]="2"
[infiniteScrollThrottle]="50"
(scrolled)="onScroll()">
<div *ngFor="let name of ['a','a','b','e','r','t','t','e','b','e','r','t','ererer','a','a','b','e','r','t','t','e','b','e','r','t','ererer']">
<div>
{{name}}
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.search-results {
height: 100px;
overflow-y: scroll;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是什么可以无限滚动?
小智 3
你不需要directives: [InfiniteScroll]。模块内的导入就足够了。
关于滚动本身 - 您是否看到对您定义的函数的调用(onScroll())?
基本上,(scrolled)每当包含该指令的元素的一定百分比(默认情况下为 80%)显示在视口中时,该指令就会调用该函数。
例如,如果您有一个高度为 500px 的表格,那么当它的 400px 进入视口(您在屏幕上看到的内容)时,将调用滚动函数。