You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Angular独立应用中设置ngZone以禁用zone.js?

独立Angular应用中设置ngZone参数的方法

在独立组件启动的Angular应用中,需通过bootstrapApplication的配置参数配合provideZoneChangeDetection函数来设置ngZone,具体实现如下:

  • 从@angular/core导入provideZoneChangeDetection
  • 在bootstrapApplication的第二个配置对象中,通过providers数组传入配置好的provideZoneChangeDetection

示例代码:

import { bootstrapApplication, provideZoneChangeDetection } from '@angular/core';
import { AppComponent } from './app/app.component';

bootstrapApplication(AppComponent, {
  providers: [
    provideZoneChangeDetection({ ngZone: 'noop' })
  ]
});

上述代码中ngZone: 'noop'的作用与模块方式里的配置完全一致,即禁用Angular的Zone。你也可根据需求传入其他有效值,比如默认的'zone.js',或者自定义的NgZone实例。

内容的提问来源于stack exchange,提问作者Eiswind

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 11:20:34