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

Angular独立组件OnPush变更检测策略报错求助

问题解决:Angular组件ChangeDetectionStrategy导入错误

你的错误根源是导入路径错误:

当前代码中,ChangeDetectionStrategy是从@angular/compiler导入的,但Angular组件配置需要的ChangeDetectionStrategy枚举实际上定义在@angular/core模块中,这就导致了类型不匹配的报错。

修复步骤:

  1. 修改导入语句,将ChangeDetectionStrategy从@angular/core导入:
import { Component, ChangeDetectionStrategy } from '@angular/core';
  1. 删除错误的导入行:
// 删掉这行
import { ChangeDetectionStrategy } from '@angular/compiler';

修改后,组件的changeDetection: ChangeDetectionStrategy.OnPush配置就能被正确识别,报错会消失。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 18:53:15