[英]How do I get Angular working in an HTA running IE 9?
I'm required to develop an HTML application (HTA) to solve a business problem. 我需要开发一个HTML应用程序 (HTA)来解决业务问题。 I consider that using Angular under the hood would greatly ease development.
我认为在后台使用Angular将大大简化开发。
I've created a new Angular project via ng new
and made some small changes (detailed below), but when I run the built HTA file, I get this error: 我已经通过
ng new
创建了一个新的Angular项目,并做了一些小的更改(在下面进行了详细介绍),但是当我运行内置的HTA文件时,出现此错误:
Error: 'console' is undefined
错误:“控制台”未定义
and the page never loads in the HTA window. 并且页面永远不会加载到HTA窗口中。
The HTA uses IE 9 (the requirements of the app prevent use of a later browser version), so the app includes this meta tag: HTA使用IE 9(该应用程序的要求禁止使用更高版本的浏览器),因此该应用程序包含以下元标记:
<meta http-equiv="X-UA-Compatible" content="IE=9">
Angular's documentation states that IE 9 is supported if I uncomment all of the necessary polyfills in polyfills.ts
, which I've done: 角的文档指出IE 9支持 ,如果我去掉所有必要的polyfills的
polyfills.ts
,我已经做了:
/** 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';
I've renamed the included index.html
file to index.hta
and made the corresponding change in .angular-cli.json
. 我已将包含的
index.html
文件重命名为index.hta
并在.angular-cli.json
进行了相应的更改。
I've tried to put the following code directly into polyfills.ts
to circumvent the missing console
: 我试图将以下代码直接放入
polyfills.ts
以规避丢失的console
:
if (!window.console) console = {error: function() {}};
but then I can't build at all, because it doesn't like me redefining console
: 但后来我根本无法构建,因为它不喜欢我重新定义
console
:
ERROR in src/polyfills.ts(77,22): error TS2322: Type '{ error: () => void; }' is not assignable to type 'Console'.
Property 'assert' is missing in type '{ error: () => void; }'.
Can anyone suggest a way forwards from here? 有人可以建议从这里前进的方法吗?
I solved this by adding the following code under the <app-root></app-root>
line in index.hta
: 我通过在
index.hta
的<app-root></app-root>
行下添加以下代码来解决此问题:
<script>
// HTAs don't have a console.
console = {};
</script>
I now get the “Welcome to app!” screen when I double-click the HTA file. 现在,当我双击HTA文件时,出现“欢迎使用应用程序!”屏幕。
It seems that Angular's build process doesn't look as closely at JavaScript declared inside the main page. 看来Angular的构建过程看起来并不像在主页内声明的JavaScript那样紧密。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.