forked from NG-ZORRO/ng-zorro-antd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
async.ts
executable file
路33 lines (29 loc) 路 1.09 KB
/
async.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
import { Component, ViewEncapsulation } from '@angular/core';
import { MentionOnSearchTypes } from 'ng-zorro-antd/mention';
@Component({
selector: 'nz-demo-mention-async',
encapsulation: ViewEncapsulation.None,
template: `
<nz-mention [nzSuggestions]="suggestions" [nzLoading]="loading" (nzOnSearchChange)="onSearchChange($event)">
<textarea rows="1" nzMentionTrigger nz-input [(ngModel)]="inputValue"></textarea>
</nz-mention>
`
})
export class NzDemoMentionAsyncComponent {
inputValue?: string;
loading = false;
suggestions: string[] = [];
onSearchChange({ value }: MentionOnSearchTypes): void {
console.log(`search: ${value}`);
this.loading = true;
this.fetchSuggestions(value, suggestions => {
console.log(suggestions);
this.suggestions = suggestions;
this.loading = false;
});
}
fetchSuggestions(value: string, callback: (suggestions: string[]) => void): void {
const users = ['afc163', 'benjycui', 'yiminghe', 'jljsj33', 'dqaria', 'RaoHai'];
setTimeout(() => callback(users.filter(item => item.indexOf(value) !== -1)), 500);
}
}