Skip to content

Commit

Permalink
fix(typeahead): resolves window items excessive rendering
Browse files Browse the repository at this point in the history
Closes #526
  • Loading branch information
maxokorokov authored and pkozlowski-opensource committed Aug 4, 2016
1 parent 0707a77 commit 862fbc5
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/typeahead/typeahead-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import {NgbHighlight} from './highlight';

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

export class ResultTplCtx {
constructor(public result, public term: string, public formatter: (result) => string) {}
}
export type ResultTplCtx = {
result: string,
term: string,
formatter: (_: string) => string
};

@Component({
selector: 'ngb-typeahead-window',
Expand All @@ -19,7 +21,8 @@ export class ResultTplCtx {
<button class="dropdown-item" [class.active]="idx === _activeIdx"
(mouseenter)="markActive(idx)"
(mousedown)="select(result)">
<template [ngTemplateOutlet]="resultTemplate || rt" [ngOutletContext]="_prepareTplCtx(result)"></template>
<template [ngTemplateOutlet]="resultTemplate || rt"
[ngOutletContext]="{result: result, term: term, formatter: formatter}"></template>
</button>
</template>
`,
Expand Down Expand Up @@ -68,6 +71,4 @@ export class NgbTypeaheadWindow {
prev() { this._activeIdx = (this._activeIdx === 0 ? this.results.length - 1 : this._activeIdx - 1); }

select(item) { this.selectEvent.emit(item); }

private _prepareTplCtx(result: any) { return new ResultTplCtx(result, this.term, this.formatter); }
}

0 comments on commit 862fbc5

Please sign in to comment.