0

How can I work with pure zone.js API (like Zone.current or creating new zones by forking) in Angular 2+ & ES2015 Modules? When I do:

import { Zone } from 'zone.js';

I get this error:

file: 'file:///c%3A/Users/InTheZone/src/main.ts'
severity: 'Error'
message: 'File 'c:/Users/InTheZone/node_modules/zone.js/dist/zone.js.d.ts' is not a module.'
at: '3,22'
source: 'ts'
code: '2306'

Typings file is there, but it does no export anything.

dragonfly
  • 17,407
  • 30
  • 110
  • 219
  • Zone is a polyfill for a proposal, not a library. It is avaliable as Zone global. It's supposed to be used in Angular via NgZone provider, – Estus Flask Dec 05 '17 at 10:02
  • NgZone does not have API to fork a new zone. Let me rephrase, how can I access Zone global with type information so that typescript compiler is happy? – dragonfly Dec 05 '17 at 10:15
  • With `Zone` global. You should already have `zone.js` imported along with other polyfills. – Estus Flask Dec 05 '17 at 10:31

1 Answers1

2

if you want to use Zone in angular project to access Zone native API, you can do like this.

declare let Zone: any;

class AppComponent {
  method() {
    Zone.current.fork({
      name: 'myZone'
    }).run(() => {
      console.log('in myzone? ', Zone.current.name);
    });
  }
}
jiali passion
  • 1,691
  • 1
  • 14
  • 19