javascript - Angular 4 - 新的 MouseEvent 导致 IE11 错误

标签 javascript angular mouseevent internet-explorer-11 angular-cli

我在 IE11 上的 Angular 4 中遇到 mouseEvent 问题。我正在使用 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 shim...

我在 Google 中找不到类似的内容,我认为这是一些愚蠢的问题 - 云有人请给我指出解决方案吗?

最佳答案

html 文件中尝试:

<div #sample>You need to click me</div>

在 component.js 文件中:

@ViewChild('sample') sampleEle: ElementRef;

并使用 js 中的点击事件:

this.sampleEle.nativeElement.click();

关于javascript - Angular 4 - 新的 MouseEvent 导致 IE11 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43655331/

相关文章:

.net - 如何在VB.NET中跟踪鼠标单击和拖动事件?

javascript - Angular2 通过 Observable 进行兄弟通信 - 最佳实践?

javascript - 无法在 JS 中使用 document.cookie 访问 cookie

css - 无法在 Angular cli 新元素中加载样式

mfc - MFC对话框中如何阻止鼠标输入

c++ - 用C++点击鼠标

javascript - 隐藏数据表中的记录

php - jQuery POST 值到 PHP 脚本

html - 为 Angular [Elements] 小部件隔离/范围所有 SCSS 样式的最简单方法是什么?

angular - 属性绑定(bind) tabItem 未被嵌入式模板上的任何指令使用