Tengo un problema con mouseEvent en angular 4 en IE11. Estoy usando angular 4, angular-cli.
Cuando activo esta línea de código:
let newEvent = new MouseEvent('mouseleave', {bubbles: true});IE está lanzando tal excepción en la consola:
TypeError: Object does not support this operation. at MenuItemComponent.prototype.onClick (./main.bundle.js:821:13) at Anonymous function (Function code:37:9) at handleEvent (./vendor.bundle.js:12039:87) at callWithDebugContext (./vendor.bundle.js:13247:9) at debugHandleEvent (./vendor.bundle.js:12835:5) at dispatchEvent (./vendor.bundle.js:9014:5) at Anonymous function (./vendor.bundle.js:9604:31) at Anonymous function (./vendor.bundle.js:19253:9) at ZoneDelegate.prototype.invokeTask (./polyfills.bundle.js:10732:13) at onInvokeTask (./vendor.bundle.js:4357:21) at ZoneDelegate.prototype.invokeTask (./polyfills.bundle.js:10732:13) at Zone.prototype.runTask (./polyfills.bundle.js:10501:21) at invoke (./polyfills.bundle.js:10796:21)
Descomenté todo en mi polyfils.ts y reconstruí el proyecto, probé IE y ES6 shims...
No puedo encontrar nada similar en Google, y creo que este es un problema tonto: ¿alguien de la nube me indica la solución?
Puedes hacer trucos para IE:
importar { Componente, OnInit, ElementRef, ViewChild } desde '@angular/core';
...
@ViewChild('fileInput') public fileInput: RefElemento;
...
// Trigger button click event let event; if (document.createEvent){ // Only for IE and Firefox event = document.createEvent('MouseEvent'); event.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); } else { // For Chrome event = new MouseEvent('click', {bubbles: false}); } this.button.nativeElement.dispatchEvent(event);Prueba en el archivo html :
<div #sample>You need to click me</div>en el archivo componente.js:
@ViewChild('sample') sampleEle: ElementRef; y el uso del evento de clic como en el js como:
this.sampleEle.nativeElement.click();