fix(platform-browser): fix #22155, destroy hammer manager when off (#22156)

PR Close #22156
This commit is contained in:
JiaLi.Passion 2018-02-12 08:35:20 +09:00 committed by Jason Aden
parent ccceff5ecc
commit 55d54c7e97
1 changed files with 8 additions and 1 deletions

View File

@ -71,6 +71,7 @@ export const HAMMER_LOADER = new InjectionToken<HammerLoader>('HammerLoader');
export interface HammerInstance {
on(eventName: string, callback?: Function): void;
off(eventName: string, callback?: Function): void;
destroy?(): void;
}
/**
@ -214,7 +215,13 @@ export class HammerGesturesPlugin extends EventManagerPlugin {
zone.runGuarded(function() { handler(eventObj); });
};
mc.on(eventName, callback);
return () => mc.off(eventName, callback);
return () => {
mc.off(eventName, callback);
// destroy mc to prevent memory leak
if (typeof mc.destroy === 'function') {
mc.destroy();
}
};
});
}