angular2-mdl-ext icon indicating copy to clipboard operation
angular2-mdl-ext copied to clipboard

[BUG] MdlPopover firing TypeError on ngOnDestroy()

Open rarenal opened this issue 8 years ago • 11 comments

Hello, I'm using MdlSelect in my project (which includes MdlPopover) and since today I am facing an error whenever I swap from a view with an MdlSelect component to another view, which fires its ngOnDestroy() method causing the next error:

ERROR Error: Uncaught (in promise): TypeError: Failed to execute 'removeEventListener' on 'EventTarget': 2 arguments required, but only 1 present. TypeError: Failed to execute 'removeEventListener' on 'EventTarget': 2 arguments required, but only 1 present. at HTMLElement.proto.(anonymous function) [as removeEventListener] (http://localhost:4200/polyfills.bundle.js:3858:46) at MdlPopoverComponent.ngOnDestroy (http://localhost:4200/vendor.bundle.js:57832:39) at callProviderLifecycles (http://localhost:4200/vendor.bundle.js:11657:18) at callElementProvidersLifecycles (http://localhost:4200/vendor.bundle.js:11626:13) .......

This error referes to the next method in node_modules//popover.js

MdlPopoverComponent.prototype.ngOnDestroy = function () { 
this.elementRef.nativeElement.removeEventListener('hide'); };
}

The error itself claims that removeEventListener needs 2 arguments instead of one, so as suggested by @tonu42 we can change it to:

MdlPopoverComponent.prototype.ngOnDestroy = function () {
 this.elementRef.nativeElement.removeEventListener(this,'hide'); 
};

and now it works perfectly, without any error.

Thank you


UPDATED on 17/7 highlighting code text and adding possible solution

rarenal avatar Jul 13 '17 10:07 rarenal

Same issue here

richardsengers avatar Jul 13 '17 13:07 richardsengers

Same here too

kleber-swf avatar Jul 13 '17 15:07 kleber-swf

i guess it's this issue: https://github.com/angular/zone.js/pull/834 - workaround: pin zone.js to 0.8.12

mseemann avatar Jul 13 '17 15:07 mseemann

Fixing zone.js to 0.8.12 made it work again. Hopefully it is fixed for 0.8.14.

Thank you for the workaround @mseemann

rarenal avatar Jul 14 '17 07:07 rarenal

Alternatively, editing popover.js line 34 will fix this problem.

Broken MdlPopoverComponent.prototype.ngOnDestroy = function() { this.elementRef.nativeElement.removeEventListener('hide'); };

Working MdlPopoverComponent.prototype.ngOnDestroy = function() { this.elementRef.nativeElement.removeEventListener(this,'hide'); };

tonu42 avatar Jul 16 '17 18:07 tonu42

Could we have an update on MdlPopover with this change? @mseemann

rarenal avatar Jul 17 '17 06:07 rarenal

Same here

zucker-rdrg avatar Jul 17 '17 10:07 zucker-rdrg

Our temporary fix: In main.ts

@import { MdlPopoverComponent } from '@angular-mdl/popover';
MdlPopoverComponent.prototype.ngOnDestroy = function () {
    this.elementRef.nativeElement.removeEventListener(this, 'hide');
};

Burjuy avatar Jul 18 '17 12:07 Burjuy

-> @angular-mdl/popover:0.6.4

btw. the signature for removeEventListener is:

removeEventListener(type: string, listener?: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;

mseemann avatar Jul 18 '17 19:07 mseemann

@mseemann @angular-mdl/popover:0.6.4 looks fixed, but looks like old version of popover is embeded in index.umd.js of select see: screen shot 2017-07-28 at 16 34 13

Quick fix would be to update select. Is this correct that its embeded there?

tb avatar Jul 28 '17 14:07 tb

fix: @angular-mdl/select:0.10.5

@tb Thx for taking a look into it! you are right. the popover stuff shouldn't be in the umd.js file. need to change the build configuration and check that it still all works.

mseemann avatar Jul 28 '17 15:07 mseemann