-
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:select): support custom option template (#689)
close #227
- Loading branch information
Showing
7 changed files
with
108 additions
and
3 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
47 changes: 47 additions & 0 deletions
47
src/showcase/nz-demo-select/nz-demo-select-pagination.component.ts
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,47 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'nz-demo-select-pagination', | ||
template: ` | ||
<nz-select style="width: 120px;" [(ngModel)]="selectedOption" (nzScrollToBottom)="scrollToBottom()"> | ||
<nz-option *ngFor="let option of options" [nzLabel]="option.label" [nzValue]="option"> | ||
</nz-option> | ||
<nz-option [nzLabel]="'disabled'" [nzDisabled]="true" [nzValue]="'disabled'" *ngIf="loading"> | ||
<ng-template #nzOptionTemplate> | ||
<i class="anticon anticon-loading anticon-spin"></i> Loading... | ||
</ng-template> | ||
</nz-option> | ||
</nz-select> | ||
`, | ||
styles : [] | ||
}) | ||
export class NzDemoSelectPaginationComponent implements OnInit { | ||
options = []; | ||
selectedOption; | ||
loading = false; | ||
index = 0; | ||
|
||
scrollToBottom() { | ||
if (!this.loading) { | ||
this.loading = true; | ||
setTimeout(() => { | ||
this.generateFakeData(); | ||
this.loading = false; | ||
}, 3000); | ||
} | ||
} | ||
|
||
generateFakeData() { | ||
for (let i = 0; i < 5; i++) { | ||
this.options.push({ value: this.index, label: `option${this.index}` }); | ||
this.index++; | ||
} | ||
} | ||
|
||
ngOnInit() { | ||
this.generateFakeData(); | ||
this.selectedOption = this.options[ 0 ]; | ||
} | ||
} | ||
|
||
|
28 changes: 28 additions & 0 deletions
28
src/showcase/nz-demo-select/nz-demo-select-template.component.ts
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,28 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'nz-demo-select-template', | ||
template: ` | ||
<nz-select style="width: 120px;" [(ngModel)]="selectedOption" nzAllowClear> | ||
<nz-option *ngFor="let option of options" [nzLabel]="option.label" [nzValue]="option"> | ||
<ng-template #nzOptionTemplate><i class="anticon" [ngClass]="'anticon-'+option.label"></i> {{option.label}}</ng-template> | ||
</nz-option> | ||
</nz-select> | ||
`, | ||
styles : [] | ||
}) | ||
export class NzDemoSelectTemplateComponent { | ||
options = [ | ||
{ value: 'android', label: 'android' }, | ||
{ value: 'apple', label: 'apple' }, | ||
{ value: 'windows', label: 'windows' }, | ||
{ value: 'ie', label: 'ie' }, | ||
{ value: 'chrome', label: 'chrome' }, | ||
{ value: 'github', label: 'github' }, | ||
{ value: 'aliwangwang', label: 'aliwangwang' }, | ||
{ value: 'dingding', label: 'dingding' }, | ||
]; | ||
selectedOption = this.options[ 0 ]; | ||
} | ||
|
||
|
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