From 92f1af86d8fca1bb87ef006b39e393403a3c284a Mon Sep 17 00:00:00 2001 From: gdi2290 Date: Mon, 8 Jun 2015 17:06:10 -0700 Subject: [PATCH] perf(RouterLink): use hostListeners for click MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit with a `` and lots of `router-link` you start to see noticeable lag since we’re not removing the listener Closes #2401 --- modules/angular2/src/router/router_link.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/angular2/src/router/router_link.ts b/modules/angular2/src/router/router_link.ts index 69878ca3be..75337a92ea 100644 --- a/modules/angular2/src/router/router_link.ts +++ b/modules/angular2/src/router/router_link.ts @@ -33,7 +33,8 @@ import {Location} from './location'; @Directive({ selector: '[router-link]', properties: ['route: routerLink', 'params: routerParams'], - lifecycle: [onAllChangesDone] + lifecycle: [onAllChangesDone], + hostListeners: {'^click': 'onClick()'} }) export class RouterLink { private _domEl; @@ -48,16 +49,17 @@ export class RouterLink { constructor(elementRef: ElementRef, private _router: Router, private _location: Location) { this._domEl = elementRef.domElement; this._params = StringMapWrapper.create(); - DOM.on(this._domEl, 'click', (evt) => { - DOM.preventDefault(evt); - this._router.navigate(this._navigationHref); - }); } set route(changes: string) { this._route = changes; } set params(changes: StringMap) { this._params = changes; } + onClick() { + this._router.navigate(this._navigationHref); + return false; + } + onAllChangesDone(): void { if (isPresent(this._route) && isPresent(this._params)) { this._navigationHref = this._router.generate(this._route, this._params);