在Angular 8中,如果你的项目目标是ES5,并且在IE11中出现问题,这可能是因为一些ES6+特性没有被完全转换为ES5。
解决这个问题的方法是使用一些polyfill库来填充IE11中缺失的功能。下面是一个使用core-js和tsconfig-paths的示例解决方案。
npm install core-js tsconfig-paths --save
polyfills.ts
的文件,并添加以下内容:import 'core-js/es6/array';
import 'core-js/es6/date';
import 'core-js/es6/function';
import 'core-js/es6/map';
import 'core-js/es6/math';
import 'core-js/es6/object';
import 'core-js/es6/parse-float';
import 'core-js/es6/parse-int';
import 'core-js/es6/reflect';
import 'core-js/es6/regexp';
import 'core-js/es6/set';
import 'core-js/es6/string';
import 'core-js/es6/symbol';
import 'core-js/es6/typed';
import 'core-js/es6/weak-map';
import 'core-js/es6/weak-set';
import 'core-js/es7/array';
import 'core-js/es7/object';
import 'tsconfig-paths/register';
这里我们导入了一些常见的ES6+功能,以及tsconfig-paths库。
main.ts
文件中添加以下内容:import './polyfills';
这将确保在应用程序启动时加载polyfills.ts文件。
tsconfig.json
文件中,将target
选项设置为es5
,并添加以下内容:"compilerOptions": {
...
"baseUrl": "./",
"paths": {
"@angular/*": [ "node_modules/@angular/*" ]
}
}
这将确保TypeScript编译器能够正确解析@angular/*
的路径。
通过执行上述步骤,你的Angular 8应用程序应该能够在IE11中正常运行。请注意,这只是一个示例解决方案,具体的解决方法可能因你的项目配置而有所不同。