0

我在IE11的angularEvent 4中遇到mouseEvent問題。我正在使用角4,角-cli。Angular 4 - 新MouseEvent導致IE11錯誤

當我激活這行代碼:

let newEvent = new MouseEvent('mouseleave', {bubbles: true}); 

IE在控制檯拋出這樣的例外:

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) 

我在polyfils.ts和rebuilded項目註釋去掉一切,我試過IE和ES6墊片...

我找不到類似的東西谷歌,我認爲這是一個愚蠢的問題 - 雲有人請告訴我解決方案?

+0

它可能是這個? http://stackoverflow.com/questions/1368536/internet-explorer-says-object-doesnt-support-this-property-or-method –

+0

不,我沒有在整個頁面上的任何id。 :) –

回答

0

可以通過欺騙的IE:

進口{元器件,的OnInit,ElementRef,ViewChild}從 '@角/芯';

...

@ViewChild( '的FileInput')公開的FileInput:ElementRef;

...

// 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);