简体   繁体   English

如何在Angular 2+和ES2015模块中导入和使用zone.js

[英]How to import and use zone.js in Angular 2+ and ES2015 Modules

How can I work with pure zone.js API (like Zone.current or creating new zones by forking) in Angular 2+ & ES2015 Modules? 如何在Angular 2+和ES2015模块中使用纯zone.js API(例如Zone.current或通过分叉创建新区域)? 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. 打字文件在那里,但是它不导出任何东西。

if you want to use Zone in angular project to access Zone native API, you can do like this. 如果要在角度项目中使用Zone来访问Zone本机API,则可以这样做。

declare let Zone: any;

class AppComponent {
  method() {
    Zone.current.fork({
      name: 'myZone'
    }).run(() => {
      console.log('in myzone? ', Zone.current.name);
    });
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM