gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 02:55:29 25 4
gpt4 key购买 nike

如何在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com