gpt4 book ai didi

Angular 4 : Infinite scroll not working

转载 作者:太空狗 更新时间:2023-10-29 17:02:33 25 4
gpt4 key购买 nike

我尝试过使用 ngx-infinite-scroll ( https://www.npmjs.com/package/angular2-infinite-scroll ) 和其他一些指令,但似乎都不起作用。

package.json

"dependencies": {
"@angular/animations": "^4.0.2",
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/compiler-cli": "^4.0.2",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0",
"@angular/platform-server": "^4.0.2",
"@angular/router": "^4.0.0",
"absurd": "^0.3.8",
"angular2-masonry": "^0.4.0",
"animate.css": "^3.5.2",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"font-awesome": "^4.7.0",
"jquery": "^3.2.1",
"jquery-slimscroll": "^1.3.8",
"metismenu": "^2.7.0",
"ng2-bs3-modal": "^0.10.4",
"ngx-infinite-scroll": "^0.5.1",
"rxjs": "^5.1.0"
}

user.component.html

<div class="row" infiniteScroll [infiniteScrollDistance]="0" 
[infiniteScrollThrottle]="300" (scrolled)="loadMore()">
<div class="col-md-3 col-sm-4" *ngFor="let user of userList">
<span>{{user.name}} ({{user.email}})</span>
</div>
</div>

user.module.ts

导入完成

import { InfiniteScrollModule } from 'ngx-infinite-scroll';

@NgModule({
imports: [
CommonModule,
FormsModule,
InfiniteScrollModule
],
declarations: [UserComponent],
providers: [],
exports: [],
})
export class UserModule { }

user.component.ts

export class UserComponent {

constructor() {}

loadMore() {
console.log('method begins');
}
}

也尝试使用主机监听器,但似乎没有发生滚动事件。它与我正在使用的应用无限滚动的类有什么关系吗?

最佳答案

document里面已经提到了。

By default, the directive listens to the window scroll event and invoked the callback. To trigger the callback when the actual element is scrolled, these settings should be configured:

  1. [scrollWindow]="false"
  2. set an explict css "height" value to the element

因此,只需将 height: 100% 放在您的容器上,您就会看到滚动被触发。

import { Component } from '@angular/core';

@Component({
selector: 'app',
styles: [
`.search-results {
height: 20rem;
overflow: scroll;
}`
],
template: `
<div class="search-results"
infiniteScroll
[infiniteScrollDistance]="2"
[infiniteScrollThrottle]="500"
(scrolled)="onScroll()"
[scrollWindow]="false">
</div>
`
})
export class AppComponent {
onScroll () {
console.log('scrolled!!')
}
}

关于 Angular 4 : Infinite scroll not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43914699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com