After implementing the code snippet in main.ts file, I encountered an issue with CustomEvent not being added to the window object correctly. Strangely, when I manually add CustomEvent using the JavaScript console, it works fine. This problem arises specifically when I click on a button that triggers the custom event named "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));
Provided below are two screenshots. The first one shows how CustomEvent is being added in main.ts, whereas the second image depicts the manual addition of CustomEvent using the JavaScript console.
Note: When using the $.isFunction in the JavaScript console, it returns "true"