angular - 在 IE9 中使用 Angular 2 需要什么?

标签 angular internet-explorer-9

我一直在尝试创建一个 Angular 2 应用程序(使用入门指南)作为模板,但虽然它在 Chrome 中运行良好,但我正在努力让它在 IE9 中运行!

基本上,应用程序在加载/运行 boot/js 时失败,并向开发人员控制台报告以下错误..

日志:错误:对象不支持此操作

有没有人有任何推荐或建议 - 甚至更好 - 一个在 IE9 中实际工作的演示?

我的 index.html 的开头如下所示...

<head>
<title ng-bind="title">xxx</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
<base href="/">

<link rel="stylesheet" href="/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">

<link rel="stylesheet" href="/css/style.css" />
<link rel="stylesheet" href="/css/main.css" />

</body>

<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.4.1/es5-sham.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.34.1/es6-sham.min.js"></script>
<script src="/app/shims_for_IE.js"></script>
<script src="https://rawgithub.com/systemjs/systemjs/0.19.6/dist/system.js"></script>
<script src="https://code.angularjs.org/tools/typescript.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.1/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.1/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.1/angular2.dev.js"></script>

<script>
    System.config({
    packages: {        
      app: {
        format: 'register',
        defaultExtension: 'js'
      }
    }
  });
  System.import('app/boot')
        .then(null, function(err){
            console.log(err);
        });
</script>

使用 https://angular.io/guide/quickstart 之后的 Angular 代码不折不扣!

更新 1: 通过更多测试(主要是在较新的 IE 浏览器中),我遇到了同样的问题,但看到了更多详细信息..

    TypeError: Object doesn't support property or method 'keys'
   at Anonymous function (http://localhost:5000/app/angular2.dev.js:783:5)
   at Anonymous function (http://localhost:5000/app/angular2.dev.js:781:3)
   at linkDynamicModule (https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.16/system.src.js:3130:5)
   at getModule (https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.16/system.src.js:3098:9)
   at Anonymous function (https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.16/system.src.js:3134:9)
   at Anonymous function (http://localhost:5000/app/angular2.dev.js:10795:3)
   at linkDynamicModule (https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.16/system.src.js:3130:5)
   at getModule (https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.16/system.src.js:3098:9)
   at Anonymous function (https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.16/system.src.js:3134:9)
   at Anonymous function (http://localhost:5000/app/angular2.dev.js:12011:3)

index.html 目前看起来像..

<head>
<title ng-bind="title">xxx</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
<base href="/">

<link rel="stylesheet" href="/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">

<link rel="stylesheet" href="/css/style.css" />
<link rel="stylesheet" href="/css/main.css" />

<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.4.1/es5-sham.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.34.1/es6-sham.min.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.1/angular2-polyfills.js"></script>

<script src="https://code.angularjs.org/tools/typescript.js"></script>

<script src="/app/reflect.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.16/system.src.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.16/system-polyfills.src.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.1/Rx.js"></script>
<!--<script src="https://code.angularjs.org/2.0.0-beta.1/angular2.dev.js"></script>-->
<script src="/app/angular2.dev.js"></script>



<script src="/app/shims_for_IE.js"></script>


<script>
    System.config({
    packages: {        
      app: {
        format: 'register',
        defaultExtension: 'js'
      }
    }
  });
  System.import('app/boot')
        .then(function(){
        }, function(err){
            console.log(err.stack);
        });
</script>

最佳答案

针对 Angular2 RC4 IE9 的修复:

  • 包含脚本:

<script src="https://npmcdn.com/angular2@2.0.0beta.17/es6/dev/src/testing/shims_for_IE.js"></script>

  • 将路由方法更改为“#”

import { LocationStrategy, HashLocationStrategy } from '@angular/common'; ... bootstrap(AppComponent, [ ..., { provide: LocationStrategy, useClass: HashLocationStrategy } ]);

  • 不要使用浏览器历史记录进行导航:

window.history.back(); //BAD

关于angular - 在 IE9 中使用 Angular 2 需要什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34775684/

相关文章:

angular - 如何使用带有参数的选择器从效果中的ngrx存储中选择

Angular 8 - 不可分配给 AsyncValidatorFn

Angular base href 没有出现在 URL 中

java - Web Windows 7 jinitiator 中的 Oracle 表单不适用于 IE9

jquery - Internet Explorer 9.0 中的背景动画不显示动画

html - IE9 中错误定位的元素,转换为 : rotate

Angular 辅助路由 - 无法在同一个导航调用中导航和清除辅助路由?

javascript - IE 9下本地存储大小不受限制?

javascript - 阻止 IE 内联弹出广告

angular - 有谁知道如何在 component.ts 文件中使用 titlecase 而不是在 html 文件中?