简体   繁体   English

Angular2 IE11 无法获取未定义或空引用的属性“应用”

[英]Angular2 IE11 Unable to get property 'apply' of undefined or null reference

I am getting the following error after upgrading my angular2 packages to the following versions:将 angular2 软件包升级到以下版本后,出现以下错误:

  • @angular/common": "^2.3.1 @angular/common": "^2.3.1
  • @angular/compiler": "^2.3.1 @angular/compiler": "^2.3.1
  • @angular/core": "^2.3.1 @angular/core": "^2.3.1
  • @angular/forms": "^2.3.1 @angular/forms": "^2.3.1
  • @angular/http": "^2.3.1 @angular/http": "^2.3.1
  • @angular/platform-browser": "^2.3.1" @angular/platform-b​​rowser": "^2.3.1"
  • @angular/platform-browser-dynamic": "^2.3.1 @angular/platform-b​​rowser-dynamic": "^2.3.1
  • @angular/platform-server": "^2.3.1 @angular/platform-server": "^2.3.1
  • @angular/router": "^3.3.1 @angular/router": "^3.3.1

Error : Unable to get property 'apply' of undefined or null reference错误Unable to get property 'apply' of undefined or null reference

在此处输入图片说明

I am only getting this error in IE11, in Chrome it works fine.我只在 IE11 中遇到这个错误,在 Chrome 中它工作正常。

I did some digging and the line that causes the error is in the angular/common module:我做了一些挖掘,导致错误的行在 angular/common 模块中:

function combine(options) {
  return (_a = ((Object))).assign.apply(_a, [{}].concat(options));
  var _a;
}

The typescript file:打字稿文件:

@angular/common/src/pipes/intl.ts line 175 @angular/common/src/pipes/intl.ts第 175 行

function combine(options: Intl.DateTimeFormatOptions[]): Intl.DateTimeFormatOptions {
  return (<any>Object).assign({}, ...options);
}

The code that calls the combine function is @angular/common/src/pipes/intl.ts line 48:调用combine函数的代码是@angular/common/src/pipes/intl.ts第 48 行:

'yMMMdjms': datePartGetterFactory(combine([


UPDATE更新

It seems that the actual error is that the .assign method is not implemented in IE11看来实际的错误是.assign方法没有在 IE11 中实现

If you are using @angular/cli and intend to support IE9-11 you can edit the src/polyfills.ts file to enable appropriate polyfills.如果您正在使用@angular/cli并打算支持 IE9-11,您可以编辑src/polyfills.ts文件以启用适当的 polyfill。 The required polyfills are already in the file so all you need to do is un-comment them.所需的 polyfills 已经在文件中,所以你需要做的就是取消注释它们。

By default @angular/cli projects target "evergreen" browsers out of the box which means that IE isn't immediately supported, but you can add support by importing polyfills for the features you need.默认情况下, @angular/cli项目以开箱即用的“常青”浏览器为目标,这意味着 IE 不会立即得到支持,但您可以通过导入 polyfills 来添加对所需功能的支持。

Angular has dependency on core-js . Angular 依赖于core-js Thereby you can use Object.assign polyfills from it:因此你可以使用Object.assign polyfills:

import "core-js/client/shim"; // or load it before other angular2 & zone.js stuff
import "zone.js";
import "reflect-metadata";

It's really annoying that the Angular Materials tutorial doesn't mention this problem. Angular Materials教程没有提到这个问题真的很烦人。 Anyone using IE11 and following their tutorial will hit this issue.任何使用 IE11 并遵循他们的教程的人都会遇到这个问题。

The solution, as others have mentioned, is to simply uncomment those lines in your project's polyfills.ts file.正如其他人所提到的,解决方案是简单地取消注释项目的polyfills.ts文件中的这些行。

在此处输入图片说明

But really, this should've been mentioned in their tutorial.但实际上,这应该在他们的教程中提到。

I'm spending far too many hours Googling to find solutions to these Angular problems...我花了太多时间在谷歌上搜索这些 Angular 问题的解决方案......

According to MDN Object.assign() Browser compatibility IE is not supported.根据MDN Object.assign()浏览器兼容性IE 不受支持。

You can import the Object.assign polyfill by MDN with npm.您可以使用 npm 通过MDN导入Object.assign polyfill。 ( mdn-polyfills ) ( mdn-polyfills )

Run: npm i mdn-polyfills --save运行: npm i mdn-polyfills --save

Use: import 'mdn-polyfills/Object.assign';使用: import 'mdn-polyfills/Object.assign';

To Work in IE browser在 IE 浏览器中工作

Step 1: Run: npm i mdn-polyfills --save第 1 步:运行: npm i mdn-polyfills --save

Step 2: Open polyfills.ts第 2 步:打开polyfills.ts

Step 3: UnComment the imports in the file under /** IE9, IE10 and IE11 requires all of the following polyfills.第3步:取消注释/**下文件中的imports IE9、IE10和IE11需要以下所有polyfill。 **/ **/

at your polyfills.ts add:在你的 polyfills.ts 添加:

import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/set';

if anyone got this error in a dotnet core 2.0 Angular template using IE, this is how I resolved it.如果有人在使用 IE 的 dotnet core 2.0 Angular 模板中遇到此错误,我就是这样解决的。

  1. install core-js安装 core-js

    npm install core-js --save npm install core-js --save

  2. Add this line at the top of ClientApp/boot.browser.ts在 ClientApp/boot.browser.ts 的顶部添加这一行

    import 'core-js/client/shim';导入 'core-js/client/shim';

If you are using angular 4.x and come across this error then the solution described in https://github.com/angular/angular-cli/issues/6036 worked for me.如果您使用的是 angular 4.x 并遇到此错误,那么https://github.com/angular/angular-cli/issues/6036 中描述的解决方案对我有用。

It seems like there is a bug with version 0.8.8 of "zone.js".似乎“zone.js”的 0.8.8 版存在一个错误。 However, downgrading back to version 0.8.4 resolved the issue.但是,降级回 0.8.4 版解决了该问题。 See the link for more details.请参阅链接查看更多细节。

Angular 4 IE11 fix for unable to get property 'apply' Angular 4 IE11 修复无法获取属性“应用”

Step 1 : Open app/boot-browser-ts第 1 步:打开 app/boot-browser-ts

Step 2 : add the below line第 2 步:添加以下行

import 'core-js/client/shim'; 

似乎 angular-cli(v1.0.0-rc.0) 有一个名为 polyfills.ts 的文件,你必须在其中取消对浏览器所有必需的 polyfill 的注释,它对我来说很好用,在 IE-11 中零安装。

Stas Berkov is correct, and his answer led me to a slightly different solution: Stas Berkov 是对的,他的回答让我找到了一个略有不同的解决方案:

In my header where I load all the Angular scripts I included shim.js.在我加载所有 Angular 脚本的标题中,我包含了 shim.js。 (I bundle/minified on deploy). (我在部署时捆绑/缩小)。 Big note: it is critical that shim.js be loaded before zone.js, otherwise you get a different error.重要提示:在 zone.js 之前加载 shim.js 至关重要,否则会出现不同的错误。

<script src="/<my domain>/node_modules/core-js/client/shim.js"></script>
<script src="/<my domain>/node_modules/zone.js/dist/zone.js"></script>
<script src="/<my domain>/node_modules/reflect-metadata/Reflect.js"></script>
<script src="/<my domain>/node_modules/systemjs/dist/system.src.js"></script>

<script src="/<my domain>/systemjs.config.js"></script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IE11无法获取未定义或空引用的属性“值” - IE11 Unable to get property 'value' of undefined or null reference 无法获取未定义或空引用的属性“应用”-IE11和Chrome - Unable to get property 'apply' of undefined or null reference - IE11 and Chrome SCRIPT5007:无法在 IE11 中获取未定义或空引用的属性“值” - SCRIPT5007: Unable to get property 'value' of undefined or null reference in IE11 AG-Grid在IE11中具有vue错误挂接钩中出现错误:“ TypeError:无法获取未定义或空引用的属性&#39;addEventListener&#39; - AG-Grid with vue error in IE11 Error in mounted hook: “TypeError: Unable to get property 'addEventListener' of undefined or null reference” IE 11无法获取未定义或空引用的属性“长度” - IE 11 Unable to get property 'length' of undefined or null reference 无法在IE 11中获得未定义或空引用的属性“样式” - Unable to get property 'style' of undefined or null reference in IE 11 无法获取未定义或空引用的属性“top”(IE 11) - Unable to get property 'top' of undefined or null reference (IE 11) Angular 2+:IE 11无法获取未定义或空引用的属性“调用” - Angular 2+: IE 11 Unable to get property 'call' of undefined or null reference 在Win7上使用IE11的Javascript运行时错误:无法设置未定义或空引用的属性“禁用” - Javascript runtime error using IE11 on Win7: Unable to set property 'disabled' of undefined or null reference Angular 4错误TypeError:无法在IE中获取未定义或空引用的属性“应用” - Angular 4 ERROR TypeError: Unable to get property 'apply' of undefined or null reference in IE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM