我在IE11上的Angular 4中有鼠标效果问题。我使用的是Angular 4,Angular-Cli。
当我激活这条代码时:
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和重建项目中没有服用所有内容,我尝试了IE和ES6垫片...
我在Google中找不到类似的东西,我认为这是一个愚蠢的问题 - 云有人请我指出解决方案?
在html
文件中尝试:
<div #sample>You need to click me</div>
在component.js文件中:
@ViewChild('sample') sampleEle: ElementRef;
和使用js
中的单击事件为:
this.sampleEle.nativeElement.click();
您可以为IE欺骗:
import {component,oninit,elementref,viewchild}来自'@angular/core';
...
@viewchild('fileInput'(public 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);