Angular 6应用在IE和Edge中无法运行。
创始人
2024-10-16 10:01:29
0

要解决Angular 6应用在IE和Edge中无法运行的问题,可以尝试以下几个步骤:

  1. 确保你的Angular应用已经正确地被编译为ES5代码,因为IE和Edge不支持ES6及以上版本的JavaScript语法。在Angular中,你可以使用“target”选项来指定编译的目标版本。在tsconfig.json文件中,将"target"的值设置为"es5":
{
  "compilerOptions": {
    "target": "es5",
    ...
  },
  ...
}
  1. 确保你的Angular应用已经引入了所需的polyfills来填充IE和Edge缺少的功能。在src/polyfills.ts文件中,确保以下polyfills被取消注释(即去掉注释符号):
/**
 * IE9, IE10 and IE11 requires all of the following polyfills.
 **/
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/weak-map';
import 'core-js/es6/set';

/**
 * IE10 and IE11 requires the following for NgClass support on SVG elements
 */
import 'classlist.js';  // Run `npm install --save classlist.js`.

/**
 * IE10 and IE11 requires the following for the Reflect API.
 */
import 'core-js/es6/reflect';
  1. 如果你的Angular应用使用了一些ES6的新特性(如箭头函数、解构赋值等),可以引入额外的polyfills来填充这些新特性。在src/polyfills.ts文件中,将以下代码取消注释,并根据你的需要引入相应的polyfills:
/***************************************************************************************************
 * Zone JS is required by default for Angular itself.
 */
import 'zone.js/dist/zone';  // Included with Angular CLI.

/***************************************************************************************************
 * APPLICATION IMPORTS
 */
import 'core-js/es7/reflect'; // Add this line to import the reflect-metadata module.

// Add more polyfills as needed, such as:
// import 'core-js/es6/array';
// import 'core-js/es6/string';
// import 'core-js/es6/map';
// import 'core-js/es6/set';
  1. 确保你的应用在index.html文件中正确地引入了所需的脚本文件。在index.html文件的标签中,确保以下脚本被引入:



  
  My App
  

  
  
  
  
  


  


请注意,你可以根据实际情况选择从本地文件引入polyfills,也可以使用CDN链接。

通过以上步骤,你的Angular 6应用应该可以在IE和Edge中正常运行了。

相关内容

热门资讯

Android Recycle... 要在Android RecyclerView中实现滑动卡片效果,可以按照以下步骤进行操作:首先,在项...
安装apache-beam==... 出现此错误可能是因为用户的Python版本太低,而apache-beam==2.34.0需要更高的P...
Android - 无法确定任... 这个错误通常发生在Android项目中,表示编译Debug版本的Java代码时出现了依赖关系问题。下...
Android - NDK 预... 在Android NDK的构建过程中,LOCAL_SRC_FILES只能包含一个项目。如果需要在ND...
Akka生成Actor问题 在Akka框架中,可以使用ActorSystem对象生成Actor。但是,当我们在Actor类中尝试...
Agora-RTC-React... 出现这个错误原因是因为在 React 组件中使用,import AgoraRTC from “ago...
Alertmanager在pr... 首先,在Prometheus配置文件中,确保Alertmanager URL已正确配置。例如:ale...
Aksnginxdomainb... 在AKS集群中,可以使用Nginx代理服务器实现根据域名进行路由。以下是具体步骤:部署Nginx i...
AddSingleton在.N... 在C#中创建Singleton对象通常是通过私有构造函数和静态属性来实现,例如:public cla...
Alertmanager中的基... Alertmanager中可以使用repeat_interval选项指定在一个告警重复发送前必须等待...