forked from NG-ZORRO/ng-zorro-antd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
certain-category.ts
107 lines (101 loc) · 2.62 KB
/
certain-category.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
export interface AutocompleteOptionGroups {
title: string;
count?: number;
children?: AutocompleteOptionGroups[];
}
@Component({
selector: 'nz-demo-auto-complete-certain-category',
encapsulation: ViewEncapsulation.None,
template: `
<div class="example-input">
<nz-input-group nzSize="large" [nzSuffix]="suffixIcon">
<input
placeholder="input here"
nz-input
[(ngModel)]="inputValue"
(ngModelChange)="onChange($event)"
[nzAutocomplete]="auto"
/>
</nz-input-group>
<ng-template #suffixIcon>
<span nz-icon nzType="search"></span>
</ng-template>
<nz-autocomplete #auto>
<nz-auto-optgroup *ngFor="let group of optionGroups" [nzLabel]="groupTitle">
<ng-template #groupTitle>
<span>
{{ group.title }}
<a class="more-link" href="https://www.google.com/search?q=ng+zorro" target="_blank">更多</a>
</span>
</ng-template>
<nz-auto-option *ngFor="let option of group.children" [nzLabel]="option.title" [nzValue]="option.title">
{{ option.title }}
<span class="certain-search-item-count">{{ option.count }} 人 关注</span>
</nz-auto-option>
</nz-auto-optgroup>
</nz-autocomplete>
</div>
`,
styles: [
`
.certain-search-item-count {
position: absolute;
color: #999;
right: 16px;
}
.more-link {
float: right;
}
`
]
})
export class NzDemoAutoCompleteCertainCategoryComponent implements OnInit {
inputValue?: string;
optionGroups: AutocompleteOptionGroups[] = [];
constructor() {}
onChange(value: string): void {
console.log(value);
}
ngOnInit(): void {
setTimeout(() => {
this.optionGroups = [
{
title: '话题',
children: [
{
title: 'AntDesign',
count: 10000
},
{
title: 'AntDesign UI',
count: 10600
}
]
},
{
title: '问题',
children: [
{
title: 'AntDesign UI 有多好',
count: 60100
},
{
title: 'AntDesign 是啥',
count: 30010
}
]
},
{
title: '文章',
children: [
{
title: 'AntDesign 是一个设计语言',
count: 100000
}
]
}
];
}, 1000);
}
}