Angular2 IE11无法获取未定义或空引用的属性“apply” [英] Angular2 IE11 Unable to get property 'apply' of undefined or null reference

查看:624
本文介绍了Angular2 IE11无法获取未定义或空引用的属性“apply”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将angular2软件包升级到以下版本后出现以下错误:

I am getting the following error after upgrading my angular2 packages to the following versions:


  • @ angular / common:^ 2.3 .1

  • @ angular / compiler:^ 2.3.1

  • @ angular / core:^ 2.3.1

  • @ angular / forms:^ 2.3.1

  • @ angular / http:^ 2.3.1

  • @ angular / platform-b​​rowser:^ 2.3.1

  • @ angular / platform-b​​rowser-dynamic:^ 2.3.1

  • @ angular / platform-server:^ 2.3.1

  • @ angular / router:^ 3.3.1

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

错误无法获取未定义或空引用的属性'apply'

我只是在IE11中收到此错误,在Chrome中它运行正常。

I am only getting this error in IE11, in Chrome it works fine.

我做了一些挖掘,导致错误的行在angular / common模块中:

I did some digging and the line that causes the error is in the angular/common module:

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

打字稿文件:

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

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

调用组合的代码函数是
@ angular / common / src / pipes / intl.ts 第48行:

'yMMMdjms':datePartGetterFactory(combine ([

更新

似乎实际的错误是IE11中没有实现 .assign 方法

It seems that the actual error is that the .assign method is not implemented in IE11

推荐答案

如果您使用 @ angular / cli 并打算支持IE9-11,您可以编辑 src / polyfills.ts 文件以启用适当的polyfill。所需的polyfill已经在文件中,所以你需要做的就是取消注释。

If you are using @angular/cli and intend to support IE9-11 you can edit the src/polyfills.ts file to enable appropriate polyfills. The required polyfills are already in the file so all you need to do is un-comment them.

默认 @ angular / cli 项目目标常青浏览器开箱即用,这意味着IE不是immedia tely支持,但您可以通过导入polyfill添加支持以获得所需的功能。

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.

这篇关于Angular2 IE11无法获取未定义或空引用的属性“apply”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆