From aad02a54d2b53df23b7db0626c0c6d32bc9f1547 Mon Sep 17 00:00:00 2001 From: Andrew Yang Date: Sat, 22 Jun 2019 21:24:01 +1000 Subject: [PATCH] feat(module:select): support custom template in select component (#3071) close #2946 --- components/select/demo/custom-template.md | 15 ++++++++++ components/select/demo/custom-template.ts | 24 +++++++++++++++ components/select/doc/index.en-US.md | 1 + components/select/doc/index.zh-CN.md | 1 + .../nz-select-top-control.component.html | 10 +++++-- .../select/nz-select-top-control.component.ts | 1 + components/select/nz-select.component.html | 1 + components/select/nz-select.component.spec.ts | 30 ++++++++++++++++++- components/select/nz-select.component.ts | 1 + 9 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 components/select/demo/custom-template.md create mode 100644 components/select/demo/custom-template.ts diff --git a/components/select/demo/custom-template.md b/components/select/demo/custom-template.md new file mode 100644 index 00000000000..19f0fc79b58 --- /dev/null +++ b/components/select/demo/custom-template.md @@ -0,0 +1,15 @@ +--- +order: 18 +title: + zh-CN: 自定义选择器内容 + en-US: Custom Select Template +--- + +## zh-CN + +通过 `nzCustomTemplate` 自定义 nz-select 显示的内容。 + +## en-US + +Custom the content of nz-select via `nzCustomTemplate`. + diff --git a/components/select/demo/custom-template.ts b/components/select/demo/custom-template.ts new file mode 100644 index 00000000000..4964039a0d0 --- /dev/null +++ b/components/select/demo/custom-template.ts @@ -0,0 +1,24 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'nz-demo-select-custom-template', + template: ` + + Windows + Mac + Android + + + Label: {{ selected.nzLabel }} Value: {{ selected.nzValue }} + + ` +}) +export class NzDemoSelectCustomTemplateComponent { + selectedOS = null; +} diff --git a/components/select/doc/index.en-US.md b/components/select/doc/index.en-US.md index 13a3c071e15..fee1b7d4d60 100644 --- a/components/select/doc/index.en-US.md +++ b/components/select/doc/index.en-US.md @@ -41,6 +41,7 @@ import { NzSelectModule } from 'ng-zorro-antd/select'; | `[nzDropdownClassName]` | className of dropdown menu | `string` | - | | `[nzDropdownMatchSelectWidth]` | Whether dropdown's with is same with select. | `boolean` | `true` | | `[nzDropdownStyle]` | style of dropdown menu | `object` | - | +| `[nzCustomTemplate]` | The custom template of select | `TemplateRef<{ $implicit: NzOptionComponent }>` | - | | `[nzServerSearch]` | nz-option will not be filtered when set to true | `boolean` | `false` | | `[nzFilterOption]` | Filter options against it. The function will receive two arguments, `inputValue` and `option`, if the function returns `true`, the option will be included in the filtered set; Otherwise, it will be excluded. | `(input?: string, option?: NzOptionComponent) => boolean;` | - | | `[nzMaxMultipleCount]` | Max selected option can be selected | `number` | `Infinity` | diff --git a/components/select/doc/index.zh-CN.md b/components/select/doc/index.zh-CN.md index dd9524cb5cc..a5ba20c5973 100644 --- a/components/select/doc/index.zh-CN.md +++ b/components/select/doc/index.zh-CN.md @@ -42,6 +42,7 @@ import { NzSelectModule } from 'ng-zorro-antd/select'; | `[nzDropdownClassName]` | 下拉菜单的 className 属性 | `string` | - | | `[nzDropdownMatchSelectWidth]` | 下拉菜单和选择器同宽 | `boolean` | `true` | | `[nzDropdownStyle]` | 下拉菜单的 style 属性 | `object` | - | +| `[nzCustomTemplate]` | 自定义选择框的Template内容 | `TemplateRef<{ $implicit: NzOptionComponent }>` | - | | `[nzServerSearch]` | 是否使用服务端搜索,当为 true 时,将不再在前端对 nz-option 进行过滤 | `boolean` | `false` | | `[nzFilterOption]` | 是否根据输入项进行筛选。当其为一个函数时,会接收 `inputValue` `option` 两个参数,当 `option` 符合筛选条件时,应返回 `true`,反之则返回 `false`。 | `(input?: string, option?: NzOptionComponent) => boolean;` | - | | `[nzMaxMultipleCount]` | 最多选中多少个标签| `number` | `Infinity` | diff --git a/components/select/nz-select-top-control.component.html b/components/select/nz-select-top-control.component.html index cf7670dcea8..913813c68a6 100644 --- a/components/select/nz-select-top-control.component.html +++ b/components/select/nz-select-top-control.component.html @@ -21,7 +21,9 @@ class="ant-select-selection-selected-value" [attr.title]="nzSelectService.listOfCachedSelectedOption[0]?.nzLabel" [ngStyle]="selectedValueStyle"> - {{ nzSelectService.listOfCachedSelectedOption[0]?.nzLabel }} + +
{{ nzSelectService.listOfCachedSelectedOption[0]?.nzLabel }}
+