Skip to content

Commit 862fbc5

Browse files
maxokorokovpkozlowski-opensource
authored andcommitted
fix(typeahead): resolves window items excessive rendering
Closes ng-bootstrap#526
1 parent 0707a77 commit 862fbc5

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/typeahead/typeahead-window.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import {NgbHighlight} from './highlight';
33

44
import {toString} from '../util/util';
55

6-
export class ResultTplCtx {
7-
constructor(public result, public term: string, public formatter: (result) => string) {}
8-
}
6+
export type ResultTplCtx = {
7+
result: string,
8+
term: string,
9+
formatter: (_: string) => string
10+
};
911

1012
@Component({
1113
selector: 'ngb-typeahead-window',
@@ -19,7 +21,8 @@ export class ResultTplCtx {
1921
<button class="dropdown-item" [class.active]="idx === _activeIdx"
2022
(mouseenter)="markActive(idx)"
2123
(mousedown)="select(result)">
22-
<template [ngTemplateOutlet]="resultTemplate || rt" [ngOutletContext]="_prepareTplCtx(result)"></template>
24+
<template [ngTemplateOutlet]="resultTemplate || rt"
25+
[ngOutletContext]="{result: result, term: term, formatter: formatter}"></template>
2326
</button>
2427
</template>
2528
`,
@@ -68,6 +71,4 @@ export class NgbTypeaheadWindow {
6871
prev() { this._activeIdx = (this._activeIdx === 0 ? this.results.length - 1 : this._activeIdx - 1); }
6972

7073
select(item) { this.selectEvent.emit(item); }
71-
72-
private _prepareTplCtx(result: any) { return new ResultTplCtx(result, this.term, this.formatter); }
7374
}

0 commit comments

Comments
 (0)