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

后端 未结 11 1261
终归单人心
终归单人心 2020-12-07 22:41

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

  • @angular/common\": \"^2.3.1
  • @angular/compiler\": \"^
相关标签:
11条回答
  • 2020-12-07 22:52

    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.

    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.

    0 讨论(0)
  • 2020-12-07 22:54

    Angular has dependency on core-js. Thereby you can use Object.assign polyfills from it:

    import "core-js/client/shim"; // or load it before other angular2 & zone.js stuff
    import "zone.js";
    import "reflect-metadata";
    
    0 讨论(0)
  • 2020-12-07 23:01

    According to MDN Object.assign() Browser compatibility IE is not supported.

    You can import the Object.assign polyfill by MDN with npm. (mdn-polyfills)

    Run: npm i mdn-polyfills --save

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

    0 讨论(0)
  • 2020-12-07 23:02

    at your polyfills.ts add:

    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';
    
    0 讨论(0)
  • 2020-12-07 23:05

    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.

    It seems like there is a bug with version 0.8.8 of "zone.js". However, downgrading back to version 0.8.4 resolved the issue. See the link for more details.

    0 讨论(0)
  • 2020-12-07 23:09

    It's really annoying that the Angular Materials tutorial doesn't mention this problem. Anyone using IE11 and following their tutorial will hit this issue.

    The solution, as others have mentioned, is to simply uncomment those lines in your project's polyfills.ts file.

    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...

    0 讨论(0)
提交回复
热议问题