-
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:cascader): support option render template (#4127)
* feat(module:cascader): support option render template close #3699 * chore: use prefixed types internally
- Loading branch information
Showing
13 changed files
with
172 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
order: 17 | ||
title: | ||
zh-CN: 自定义选择项 | ||
en-US: Custom option template | ||
--- | ||
|
||
## zh-CN | ||
|
||
自定义选项的模板。 | ||
|
||
## en-US | ||
|
||
Custom cascader option template. | ||
|
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,56 @@ | ||
// tslint:disable:no-any | ||
import { Component } from '@angular/core'; | ||
|
||
const options = [ | ||
{ | ||
label: 'Ant Design', | ||
value: 'antd', | ||
children: [ | ||
{ | ||
label: 'ng-zorro-antd', | ||
value: 'ng-zorro-antd', | ||
isLeaf: true | ||
} | ||
] | ||
}, | ||
{ | ||
label: 'Angular', | ||
value: 'angular', | ||
children: [ | ||
{ | ||
label: 'CDK', | ||
value: 'cdk', | ||
isLeaf: true | ||
} | ||
] | ||
} | ||
]; | ||
|
||
@Component({ | ||
selector: 'nz-demo-cascader-custom-template', | ||
template: ` | ||
<nz-cascader | ||
[nzOptionRender]="renderTpl" | ||
[nzOptions]="nzOptions" | ||
[(ngModel)]="values" | ||
(ngModelChange)="onChanges($event)" | ||
> | ||
</nz-cascader> | ||
<ng-template #renderTpl let-option let-index="index"> {{ index + 1 }}. {{ option.label }} </ng-template> | ||
`, | ||
styles: [ | ||
` | ||
.ant-cascader-picker { | ||
width: 300px; | ||
} | ||
` | ||
] | ||
}) | ||
export class NzDemoCascaderCustomTemplateComponent { | ||
nzOptions = options; | ||
values: any[] | null = null; | ||
|
||
onChanges(values: any): void { | ||
console.log(values, this.values); | ||
} | ||
} |
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,6 +1,12 @@ | ||
<span [innerHTML]="optionLabel | nzHighlight: highlightText: 'g': 'ant-cascader-menu-item-keyword'"></span> | ||
<span | ||
*ngIf="!option.isLeaf || option.children && option.children.length || option.loading" | ||
class="ant-cascader-menu-item-expand-icon"> | ||
<i nz-icon [nzType]="option.loading ? 'loading' : 'right'"></i> | ||
<ng-container *ngIf="optionTemplate; else defaultOptionTemplate"> | ||
<ng-template [ngTemplateOutlet]="optionTemplate" | ||
[ngTemplateOutletContext]="{ $implicit: option, index: columnIndex }"></ng-template> | ||
</ng-container> | ||
<ng-template #defaultOptionTemplate> | ||
<span [innerHTML]="optionLabel | nzHighlight: highlightText: 'g': 'ant-cascader-menu-item-keyword'"></span> | ||
</ng-template> | ||
<span *ngIf="!option.isLeaf || option.children?.length || option.loading" | ||
class="ant-cascader-menu-item-expand-icon"> | ||
<i nz-icon | ||
[nzType]="option.loading ? 'loading' : 'right'"></i> | ||
</span> |
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
Oops, something went wrong.