这是我的 Angular 版本:
Angular CLI: 12.2.6
Node: 16.13.2 (Unsupported)
Package Manager: npm 8.1.2
OS: win32 x64
Angular: 12.2.6
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, material, material-moment-adapter, platform-browser
... platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1202.6
@angular-devkit/build-angular 12.2.6
@angular-devkit/core 12.2.6
@angular-devkit/schematics 12.2.6
@angular/flex-layout 12.0.0-beta.35
@schematics/angular 12.2.6
rxjs 6.6.3
typescript 4.2.4
我有一个 Angular 应用程序,可以在最新版本的 Chrome 和 Edge 上正常运行,但我们的大多数客户都在使用 IE11,或者真正的旧版 Chrome(例如:Chrome 45)。所以我需要使应用程序与所有这些浏览器兼容。
我尝试先解决 IE 11 的问题。到达应用程序主页时,我最初有一个空白页面。
我做了以下更改:
- 我已将
tsconfig
文件更改如下:
"target": "es5",
"lib": [
"es5",
"es2015.promise",
"es6",
"es7",
"es2018",
"dom"
]
- 我已将我的
polyfill.ts
文件更新如下:
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/guide/browser-support
*/
/***************************************************************************************************
* BROWSER POLYFILLS
*/
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
//import 'classlist.js'; // Run `npm install --save classlist.js`.
import 'core-js/es/symbol';
import 'core-js/es/object';
import 'core-js/es/function';
import 'core-js/es/parse-int';
import 'core-js/es/parse-float';
import 'core-js/es/number';
import 'core-js/es/math';
import 'core-js/es/string';
import 'core-js/es/date';
import 'core-js/es/array';
import 'core-js/es/regexp';
import 'core-js/es/map';
import 'core-js/es/weak-map';
import 'core-js/es/set';
import 'core-js/es/promise';
/**
* Web Animations `@angular/platform-browser/animations`
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
*/
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
/**
* By default, zone.js will patch all possible macroTask and DomEvents
* user can disable parts of macroTask/DomEvents patch by setting following flags
* because those flags need to be set before `zone.js` being loaded, and webpack
* will put import in the top of bundle, so user need to create a separate file
* in this directory (for example: zone-flags.ts), and put the following flags
* into that file, and then add the following code before importing zone.js.
* import './zone-flags.ts';
*
* The flags allowed in zone-flags.ts are listed here.
*
* The following flags will work for all browsers.
*
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
*
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
* with the following flag, it will bypass `zone.js` patch for IE/Edge
*
* (window as any).__Zone_enable_cross_context_check = true;
*
*/
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
(window as any).__Zone_enable_cross_context_check = true;
import 'zone.js/dist/zone'; // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS
*/
- 我已经更新了我的
browserslist
文件如下
> 0.5%
last 2 versions
Firefox ESR
not dead
IE 9-10 # For IE 9-11 support, remove 'not'.
- 我有以下 babelrc 文件:
{
"presets": [
["@babel/presets-env", {
"targets": {
"browsers": {
"ie": "11"
}
},
}]
]
}
有了这个配置,在 IE 11 中我终于可以看到我的登录页面了。我的登录页面有以下“登录”按钮:
<div>
<button mat-flat-button [disabled]="!this.credentials.password"
[ngClass]="{'button-action': this.credentials.login && this.credentials.password}" class=" full-width "
(click)="alert('lalalalala')"><span class="fs-12 light">LOGIN</span></button>
</div>
- 我真的需要 babelrc 文件还是只需要更新 tsconfig 文件和 polyfill.ts 文件?
alert
Angular 材料不支持 IE11是不是事件未触发的原因onclick
?- 我尝试使用 Firefox 42 启动我的应用程序,但出现以下我不明白的错误:
TypeError: client.onOpen is not a function
Unhandled Promise rejection: zone.onStable.emit is not a function ; Zone: <root> ; Task: Promise.then ; Value: TypeError: zone.onStable.emit is not a function
谢谢您的帮助!
编辑:我能够尝试/捕获登录调用并警告错误。错误是ReferenceError: crypto is not defined
。有任何想法吗?