如何让@HostListener在IE 11中运行?

时间:2017-08-31 10:48:02

标签: angular internet-explorer

我正在构建一个角度应用程序。我正在使用@HostListener,它在firefox,safari和chrome中运行良好,但是当我在Internet Explorer 11上运行它时,它不起作用。有没有办法让这项工作?代码看起来像这样。

@HostListener('window:scroll', ['$event']) onScrollEvent($event){
    console.log("hi");

}

以上打印到hi在控制台上滚动safari,chrome和firefox,但在IE11上不起作用。如何在IE11上完成这项工作?

我的package.json看起来像这样

{
  "name": "inloggning",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.3.1",
    "@angular/cdk": "2.0.0-beta.8",
    "@angular/common": "^4.0",
    "@angular/compiler": "^4.0",
    "@angular/compiler-cli": "^4.0",
    "@angular/core": "^4.0",
    "@angular/forms": "^4.0",
    "@angular/http": "^4.0",
    "@angular/material": "2.0.0-beta.8",
    "@angular/platform-browser": "^4.0",
    "@angular/platform-browser-dynamic": "^4.0",
    "@angular/router": "^4.0",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.4.1",
    "ng2-ckeditor": "^1.1.7",
    "rxjs": "^5.1.0",
    "web-animations-js": "^2.3.1",
    "zone.js": "^0.7.6"
  },
  "devDependencies": {
    "@angular/cli": "1.0.0-rc.2",
    "@angular/compiler-cli": "^2.4.0",
    "@types/jasmine": "2.5.38",
    "@types/node": "~6.0.60",
    "codelyzer": "~2.0.0",
    "enhanced-resolve": "3.3.0",
    "jasmine-core": "~2.5.2",
    "jasmine-spec-reporter": "~3.2.0",
    "karma": "~1.4.1",
    "karma-chrome-launcher": "~2.0.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^0.2.0",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.0",
    "ts-node": "~2.0.0",
    "tslint": "~4.5.0",
    "typescript": "~2.2.1"
  }
}

1 个答案:

答案 0 :(得分:0)

尝试以下类似方法

window.addEventListener("scroll", function (event) {
    console.log("hi");
})