When I added the following code to main.ts, CustomEvent is not added to window object correctly. If I add CustomEvent using the JavaScript console it does. Incidentally, the issue occurs when I click on a button that triggers my custom event (called: "choice-click").
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
function CustomEvent ( event, params ) {
params = params || { bubbles: false, cancelable: false, detail: undefined };
var evt = document.createEvent( 'CustomEvent' );
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
return evt;
}
CustomEvent.prototype = (<any>window).Event.prototype;
(<any>window).CustomEvent = CustomEvent;
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
Below are two screen shots. First one, main.ts adds CustomEvent. Second one, I add CustomEvent using the JavaScript console.
Note: $.isFunction returns "true" when I use the JavaScript console