我遇到了一个问题,我的基于Angular 7的应用程序不能在IE 11中工作。
我使用的是npm包,它以index.js
开头,从
class PackageClass {
// code
}
在所有浏览器中,它都运行得很好,它做它应该做的事情。但在IE11浏览器中,甚至无法打开应用程序,它会失败,并显示一个错误:Syntax error. File: vendor.js line ...
。错误导致类定义。
我已经在应用程序中使用的多边形填充:
/** 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';
/**
* Required to support Web Animations `@angular/platform-browser/animations`.
* Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
**/
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS
*/
import 'core-js/es7/object';
import 'core-js/es7/array';
我如何解决它(在IE11中运行我的应用程序)?我认为polyfills应该做这项工作。
发布于 2019-07-11 13:31:35
IE浏览器不支持JavaScript类,您可以检查JavaScript Classes Browser compatibility。
在angular 7应用程序中,如果我们想定义一个类,我们可以使用typescript创建一个类。
例如,在src/app文件夹中创建一个名为hero.ts的Hero类。
src/app/hero.ts中的代码
export class Hero {
id: number;
name: string;
}
然后在component类中,我们可以导入Hero类,并使用以下代码使用Hero类:
import { Component, OnInit } from '@angular/core';
import { Hero } from '../hero';
@Component({
selector: 'app-heroes',
templateUrl: './heroes.component.html',
styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {
hero: Hero = {
id: 1,
name: 'Windstorm'
};
constructor() { }
ngOnInit() {
}
}
有关angular应用程序的更多详细信息,请查看angular document。
此外,还有另一种方法,您可以使用babel将代码转换为ES5
https://stackoverflow.com/questions/56972692
复制相似问题