-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(module:list): add list component (#1031)
* wip(module:list): add list component - add third libs with share.module * fix lint & clean invalid code * Use NzUpdateHostClassService Instead of class operation * update test status * fix string and template invalid switched * fix tslint * fix nz-card
- Loading branch information
Showing
24 changed files
with
700 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
order: 6 | ||
title: | ||
zh-CN: 滚动加载 | ||
en-US: Scrolling loaded | ||
--- | ||
|
||
## zh-CN | ||
|
||
结合 [ngx-infinite-scroll](https://github.com/orizens/ngx-infinite-scroll) 实现滚动自动加载列表。 | ||
|
||
## en-US | ||
|
||
The example of infinite load with [ngx-infinite-scroll](https://github.com/orizens/ngx-infinite-scroll). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// tslint:disable:no-any | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { NzMessageService } from 'ng-zorro-antd'; | ||
|
||
const fakeDataUrl = 'https://randomuser.me/api/?results=5&inc=name,gender,email,nat&noinfo'; | ||
|
||
@Component({ | ||
selector: 'nz-demo-list-infinite-load', | ||
template: ` | ||
<div class="demo-infinite-container" | ||
infiniteScroll | ||
[infiniteScrollDistance]="2" | ||
[infiniteScrollThrottle]="50" | ||
(scrolled)="onScroll()" | ||
[scrollWindow]="false"> | ||
<nz-list [nzDataSource]="data"> | ||
<ng-template #item let-item> | ||
<nz-list-item> | ||
<nz-list-item-meta | ||
[nzTitle]="nzTitle" | ||
nzAvatar="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" | ||
[nzDescription]="item.email"> | ||
<ng-template #nzTitle> | ||
<a href="https://ng.ant.design">{{item.name.last}}</a> | ||
</ng-template> | ||
</nz-list-item-meta> | ||
</nz-list-item> | ||
</ng-template> | ||
<nz-spin *ngIf="loading && hasMore" class="demo-loading"></nz-spin> | ||
</nz-list> | ||
</div> | ||
`, | ||
styles: [ ` | ||
:host ::ng-deep .demo-infinite-container { | ||
border: 1px solid #e8e8e8; | ||
border-radius: 4px; | ||
overflow: auto; | ||
padding: 8px 24px; | ||
height: 300px; | ||
} | ||
:host ::ng-deep .demo-loading { | ||
position: absolute; | ||
bottom: -40px; | ||
left: 50%; | ||
} | ||
` ] | ||
}) | ||
export class NzDemoListInfiniteLoadComponent implements OnInit { | ||
data: any[] = []; | ||
loading = false; | ||
hasMore = true; | ||
|
||
constructor(private http: HttpClient, private msg: NzMessageService) {} | ||
|
||
ngOnInit(): void { | ||
this.getData((res: any) => this.data = res.results); | ||
} | ||
|
||
getData(callback: (res: any) => void): void { | ||
this.http.get(fakeDataUrl).subscribe((res: any) => callback(res)); | ||
} | ||
|
||
onScroll(): void { | ||
if (this.loading) return; | ||
this.loading = true; | ||
if (this.data.length > 14) { | ||
this.msg.warning('Infinite List loaded all'); | ||
this.hasMore = false; | ||
this.loading = false; | ||
return; | ||
} | ||
this.getData((res: any) => { | ||
this.data = this.data.concat(res.results); | ||
this.loading = false; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
export { NzListItemMetaComponent } from './nz-list-item-meta.component'; | ||
export { NzListItemComponent } from './nz-list-item.component'; | ||
export { NzListComponent } from './nz-list.component'; | ||
export * from './interface'; | ||
export { NzListModule } from './nz-list.module'; | ||
export * from './public-api'; |
Oops, something went wrong.