首页 > 解决方案 > 当我将“changeDetectionStrategy”添加到我的应用程序时出现错误

问题描述

我正在前端使用 Angular7 构建我的第一个 CRUD、Spring/hib。当我尝试在我的 component.ts 中添加 changeDetectionStrategy 时,我收到以下警告:

WARNING in ./node_modules/@angular/compiler/src/core.js
10:24-31 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

WARNING in ./node_modules/@angular/compiler/src/selector.js
10:24-31 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

WARNING in ./node_modules/@angular/compiler/src/ml_parser/html_tags.js
10:24-31 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

WARNING in ./node_modules/@angular/compiler/src/ml_parser/tags.js
10:24-31 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted.

该应用程序还有其他可以正常工作的组件,并且它们具有 changeDetectionStrategy 导入。当我将该方法添加到我的组件时,角度会给我这些错误。我评论了所有组件,除了@Component 的东西和“导出类 XY { }。错误一直存在,直到我删除 changeDetectionStrategy。知道它可能是什么吗?

标签: angularwarningsangular2-changedetection

解决方案


我认为这是由于 changeDetectionStrategey 的错误导入

import { ChangeDetectionStrategy } from '@angular/compiler/src/core';

用正确的替换它

import { ChangeDetectionStrategy } from '@angular/core';

推荐阅读