Error in Angular2: Internet Explorer 11 is having trouble accessing the property 'apply' because it is either undefined or null

After upgrading my angular2 packages to the latest versions, I encountered the following error:

  • @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

Error:

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

https://i.sstatic.net/xE5EY.png

This error only occurs in IE11, while it works fine in Chrome.

Investigating further, the error seems to be triggered in the angular/common module:

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

The corresponding typescript file:

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

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

The combine function is called in the code snippet at @angular/common/src/pipes/intl.ts line 48:

'yMMMdjms': datePartGetterFactory(combine([


UPDATE

Upon further investigation, it appears that the issue lies in the fact that the .assign method is not supported in IE11

Answer №1

If you are using @angular/cli and aiming to cater to IE9-11, you have the option to adjust the src/polyfills.ts file to activate the necessary polyfills. These essential polyfills are already present in the file, simply waiting to be uncommented.

By default, @angular/cli projects are configured to target "evergreen" browsers, which automatically excludes support for IE. However, you can easily enhance your project by incorporating polyfills for the specific features required for IE compatibility.

Answer №2

One of the dependencies of Angular is core-js. This allows you to utilize polyfills for Object.assign from it:

import "core-js/client/shim"; // Alternatively, make sure to load it before other angular2 & zone.js components
import "zone.js";
import "reflect-metadata";

Answer №3

It's frustrating how the Angular Materials tutorial fails to address this issue. If you're using IE11 and following their tutorial, you'll definitely encounter this problem.

As others have pointed out, the solution is to simply uncomment those lines in your project's polyfills.ts file.

https://i.sstatic.net/wEIu2.png

However, it really should have been addressed in their tutorial.

I'm wasting too many hours searching on Google for solutions to these Angular issues...

Answer №4

MDN's documentation on the compatibility of Object.assign() states that IE does not support it.

To address this, you can add the Object.assign polyfill from MDN using npm. (mdn-polyfills)

Installation: npm i mdn-polyfills --save

Usage:

import 'mdn-polyfills/Object.assign';

Answer №5

How to Enable Compatibility with Internet Explorer Browser

First Step: Install:npm i mdn-polyfills --save

Second Step: Access polyfills.ts

Third Step: Uncomment the necessary imports in the file located under /** Polyfills required for IE9, IE10, and IE11 **/

Answer №6

To enhance your polyfills.ts file, include the following:

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';

Answer №7

If you encounter the aforementioned error while working with a dotnet core 2.0 Angular template in IE, here is how I managed to resolve it.

  1. Start by installing core-js

    Run npm install core-js --save

  2. Next, include this line at the top of ClientApp/boot.browser.ts

    Import 'core-js/client/shim';

Answer №8

If you encounter an error while using angular 4.x, the solution outlined in https://example.com/solution may be helpful.

It appears that there is a known issue with version 0.8.8 of "zone.js". However, reverting back to version 0.8.4 seems to have resolved the issue. Visit the provided link for more information.

Answer №9

Solution for 'apply' error in Angular 4 when using IE11 No. 1 : Navigate to app/boot-browser-ts No. 2 : Insert the following line import 'core-js/client/shim';

Answer №10

angular-cli version 1.0.0-rc.0 includes a file named polyfills.ts where all necessary polyfills for various browsers can be uncommented. I found that it worked seamlessly for me in IE-11 without any additional installations.

Answer №11

After carefully considering Stas Berkov's input, I found a unique approach to solving the issue:

In the header section where I include all Angular scripts, I made sure to add shim.js. This file is essential for the correct functioning of the application (especially after bundling and minifying during deployment). It's worth noting that shim.js must be loaded before zone.js to avoid encountering a different error.

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to activate flashlight on mobile using React.Js

Is it possible to control the torch light of a mobile device by toggling a button? https://i.stack.imgur.com/x9nIf.png <IconButton onClick={() => setFlashOn(!flashOn)} style={{ position: "absolute", right: 80, top: 20, zIndex: ...

Setting up @cypress/code-coverage with Angular and TypeScript: A comprehensive guide

When following the instructions in Cypress documentation for @cypress/code-coverage, it recommends using the following code... // cypress/support/e2e.js import '@cypress/code-coverage/support' ...as well as... // cypress.config.ts import { defin ...

JavaScript - Returning an object using a promise

I'm facing an issue where I am struggling to retrieve an object with a specific structure, but I am unable to successfully return the object. When I inspect the code, I notice that if I log the data inside the promise, it shows the data. However, whe ...

Using Javascript/React to filter an array by a specific value

{ "team_group": ["Alex Smith", "Jake Brown", "Sarah King"], "group_data": { "Alex Smith": { "status": "member" }, "Jake Brown": { "status": &qu ...

Ways to check the functionality of the secondary tier in the api.send method

Currently, I am testing a function that involves returning a promise and subsequently calling the same function again at a second level. However, I am facing difficulties in accessing this second level of call. Below is the function code: itemToForm = () ...

Triggering the click event three times on a dynamically generated element

I am currently facing a simple issue. I am attempting to implement a click event on dynamically generated elements such as this: $(document).ready(function(){ $('ul').on('click', 'li.clickable', function() { conso ...

Assign the textbox's value to be the earliest selected date from the datepicker

Can anyone assist me? I have a working code that activates only the specific day of the week I want on the datepicker. However, the textbox doesn't have a default value and I would like it to display the first date activated in the datepicker. In th ...

React-Bootstrap Table Toolkit Encounter Search Import Issue

I encountered an issue while trying to integrate React Bootstrap Table into my project, resulting in the following error message. Uncaught ReferenceError: arguments is not defined at Object../node_modules/react-bootstrap-table2-toolkit/lib/src/search/Sea ...

How to deactivate a text box within a form that is dynamically generated using Angular

I have encountered an issue with disabling the textbox inside my dynamic form in AngularJS after clicking a button. My code works perfectly fine for disabling textboxes outside the dynamic form, but when I try to target the ID of the textbox within the dyn ...

Utilizing ng-repeat, ng-grid, and ng-click in Angular: A comprehensive guide

I'm encountering an issue with populating a table using ng-repeat after a cellTemplate ng-click. cellTemplate: '<div ng-click="foo()" ng-bind="row.getProperty(col.field)"></div>' Within this foo method, I am tryi ...

Tips for managing the visibility of raised errors in Firebase functions

Utilizing async/await in my firebase functions poses the challenge of managing potential errors with each call. I am unsure of the best approach to handle catching these errors. Wrapping every call in a try/catch block seems cumbersome given the use of the ...

Import files from local directory to iframe in Electron application

I am currently working on an application using Electron that allows users to preview HTML5 banner ads stored locally on their computer. At this point, I have enabled the ability to choose a folder containing all the necessary files. Once a directory is s ...

How can I make sure the page scrolls to the top when navigating from one component to another in Angular 4 (now 5)?

Recently, I've encountered a problem with routing in my Angular 5 project. My CLI version is 1.5.2. The issue arises when transitioning from one route to another. If I scroll down on the page and then navigate back to the previous route, the page rem ...

What is the proper method for running a script using the Selenium JavascriptExecutor?

On my test.html page, I've included the following code snippet: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> </head> <body> ...

I have encountered limitations with useFormik where it does not accept null values for initialValues, even while utilizing a validationSchema

I am currently utilizing the useFormik hook to handle my form. The userId field is a select, so by default its value is set to null. However, my validationSchema requires this field to be populated before submission. const formik = useFormik<ApiCredit ...

ui-grid-draggable-rows mistakenly identifies my data as a simple string

After successfully setting up the ui-grid-draggable-rows functionality by following the provided instructions, I encountered an error while running the code snippet from the example here. The error message I received is as follows: TypeError: this.spli ...

"Exploring the capabilities of Rxjs ReplaySubject and its usage with the

Is it possible to utilize the pairwise() method with a ReplaySubject instead of a BehaviorSubject when working with the first emitted value? Typically, with a BehaviorSubject, I can set the initial value in the constructor allowing pairwise() to function ...

Implementing a delete functionality within a loop on a JavaScript object array

I have a JavaScript object with the following structure: var partner = { p_name: { value: partner_name, label: "Name" }, p_id: { value: partner_ID, label: "ID" }, p_status: { value: partner_status, label: "Status" }, p_email: { value: partner_emai ...

Upgrade your project from Angular 5 to Angular 9 using webpack

I want to share my experience, not ask a question! To upgrade dependencies in package.json: -Update all Angular dependencies to version 9 -Add these dependencies: "@angular-devkit/build-angular": "^0.900.4", "@angular-builders/cu ...

Tips for repairing texture distortion on rounded corner surfaces in the three.js library

I managed to create a unique rounded corner plane by combining circle and plane geometries in my project. While the flat color in the rendered version looks great, I noticed that the textured part seems to get distorted and chopped up. If you want to tak ...