Angular 4将全局常量提供给zone.js [英] Angular 4 put a global constant available to zone.js
本文介绍了Angular 4将全局常量提供给zone.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将Angular(我认为是4)与Typescript和zone.js(0.8.4)配合使用.我通过"polyfills.ts"文件导入zone.js.当我查看zone.js的源代码时,有这样的代码:
i am using Angular (4 i think) with typescript and zone.js (0.8.4). I import zone.js via the "polyfills.ts" file. When I look inside the source code of zone.js, there is code like this:
var isDisableIECheck = _global['__Zone_disable_IE_check'] || false;
我的问题是,如何在_globals中设置此变量?
My question is, how can I set this variable in _globals ?
谢谢
推荐答案
global
是浏览器中的window
对象,如下所示:
global
is window
object in a browser as can be seen here:
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
(factory());
}(this, <------------ `this` points to `window` in global scope
(function () {
...
});
因此您可以像这样设置变量:
so you can set the variable like this:
window['__Zone_disable_IE_check'] = true;
但是您需要在 加载zone.js
之前执行此操作.如果在index.html
中加载zone.js
,请添加以下内容:
But you need to do that before zone.js
is loaded. If you load zone.js
in index.html
, add the following:
<script>
window['__Zone_disable_IE_check'] = true;
</script>
<script src="node_modules/zone.js/dist/zone.js"></script>
这篇关于Angular 4将全局常量提供给zone.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文