Angular 4 put a global constant available to zone.js
Asked Answered
E

2

7

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;

My question is, how can I set this variable in _globals ?

Thanks

Expanded answered 15/8, 2017 at 11:20 Comment(4)
why do you need that?Beilul
I need to set this one: _global['__Zone_enable_cross_context_check'] Because otherwise i get an IE error.Expanded
github.com/angular/zone.js/blob/master/lib/browser/…Expanded
On line 82 (delegate)Expanded
B
11

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;

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>
Beilul answered 15/8, 2017 at 12:51 Comment(3)
Maybe you can have a look at my related post: #45676281Expanded
I tried to put the window var before zone in the "polyfills.ts" file, where most (all?) of the JS is generated, I could see it (window['__Zone_enable_cross_context_check'] = true;) in the web source code, put didn't work.Expanded
put in the in the index.html before all polyfills are loaded. putting it in the polyfills.ts won't work because all imports are executed before the polyfills.tsBeilul
B
1

In my case, I have had to uncomment the following line in the polyfills file:

(window as any).__Zone_enable_cross_context_check = true;

Project Angular version: Angular 6.0.1

Boigie answered 13/2, 2019 at 11:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.