在 Angular 16.1.5 中,Zone.current.get() 函数是不存在的。如果你需要获取当前的 Zone,可以使用 Zone.current 属性。
以下是一个示例代码,展示如何在 Angular 16.1.5 中获取当前的 Zone:
import { Component, NgZone } from '@angular/core';
@Component({
selector: 'app-example',
template: `
`
})
export class ExampleComponent {
constructor(private zone: NgZone) {}
runTask() {
console.log('Current Zone:', this.zone);
}
}
在这个示例中,我们通过在构造函数中注入 NgZone 服务来获取当前的 Zone。然后,在 runTask() 方法中,我们可以通过 this.zone 来访问当前的 Zone。
请注意,Zone 对象在不同版本的 Angular 中可能存在差异,因此如果你使用的是其他版本的 Angular,请查阅相应的文档以了解如何获取当前的 Zone。