如何在 Angular 2+ 和 ES2015 模块中使用纯 zone.js
API(例如 Zone.current
或通过 fork 创建新区域)?当我这样做时:
import { Zone } from 'zone.js';
我收到此错误:
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'
打字文件存在,但它不导出任何内容。
最佳答案
如果你想在 Angular 项目中使用 Zone 来访问 Zone 原生 API,你可以这样做。
declare let Zone: any;
class AppComponent {
method() {
Zone.current.fork({
name: 'myZone'
}).run(() => {
console.log('in myzone? ', Zone.current.name);
});
}
}
关于javascript - 如何在 Angular 2+ 和 ES2015 模块中导入和使用 zone.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47649901/