解决这个问题的方法是添加Polyfills(垫片)来支持在IE浏览器中运行Angular应用。Polyfills是一组代码片段,它们为旧版本的浏览器模拟一些新特性。
以下是一个示例代码,演示如何在Angular应用中添加Polyfills来支持IE浏览器:
npm install --save core-js
// Polyfills required to support running Angular applications on IE browsers
// Add global to window, assigning the value of window itself.
(window as any).global = window;
// Required for core-js/es7/reflect
import 'core-js/es7/reflect';
// Zone JS is required by Angular itself.
import 'zone.js/dist/zone';
"scripts": [
"src/polyfills.ts"
]
"compilerOptions": {
"target": "es5",
...
}
ng serve
现在,您的Angular应用应该能够在IE浏览器中正确运行了。请注意,这只是一个基本示例,实际应用可能需要更多的Polyfills和配置。