Angular2: Object doesn't support this action i

2019-08-17 01:38发布

问题:

My angular2 application throws exception stating Object doesn't support this action only in Microsoft edge. Please check the below image:

I debugged and found out that the exception is thrown at promise then code. To be more specific, I am getting the error at then on below code:

this.dataLayerService
            .postLogin(this.model, this.postURL)
            .then(usermasterResponse => this.setToken(usermasterResponse))
            .catch(error => {
                  this.toastCommunicationService.setMessage(error, "",
                    this.toastCommunicationService.errorType)
            });

I have also added below script in the index.html file, but it was also in vain.

<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.34.1/es6-shim.js"></script>

Any help would be highly appreciated.

Thanks in advance.

回答1:

Put <meta http-equiv="x-ua-compatible" content="ie=edge"> in your index.html And also check your polyfills script and import all core-js/es6/ scripts



回答2:

Find your polyfills.ts file in your angular project folder and import following lines:

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es7/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';
import 'core-js/es7/array';

If you are using web-animations, so you need this:

/** IE10 and IE11 requires the following to support `@angular/animation`. */
import 'web-animations-js';  // Run `npm install --save web-animations-js`.

For evergreen browsers your need this:

/** Evergreen browsers require these. **/
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';

Evergreen browsers definition (original):

The latest versions of Chrome, Firefox, Internet Explorer, and Safari are evergreen browsers, i.e. they automatically update themselves silently without prompting the user. For Internet Explorer, most people consider this to mean IE10+.



回答3:

The issue was with the EventSource in the below code:

this.eventsource = new EventSource(this.configService.get("BaseURL"));

I got it resolved by adding Event Source Polyfill js. I followed this EventSource Polyfill link to install the js.

Thanks everyone for the help.