【发布时间】:2018-05-08 01:09:18
【问题描述】:
https://github.com/angular/angular-cli/pull/6813 添加了循环依赖的警告,我知道我可以使用 "showCircularDependencies": false 关闭所有警告。但我宁愿保持循环依赖警告。 是否有一种模式可以让我修复下面的用例,或者有没有办法专门禁用特定文件上的循环依赖插件?
最简单的情况是如果我有 3 个文件:
forms.model.ts
import { CustomModel } from './custom.model';
import { CustomForm } from './custom.form';
export class Forms {
items: CustomForm[] = [];
public constructor(models?: CustomModel[]) {
models.forEach(model => this.items.push(new CustomForm(model)));
}
}
custom.model.ts
export class CustomModel {
nestedModels: CustomModel[];
}
custom.form.ts
import { Forms } from './forms.model';
import { CustomModel } from './custom.model';
export class CustomForm {
nestedForms: Forms;
constructor(model: CustomModel) {
this.nestedForms = new Forms(model.nestedModels);
}
}
这会导致以下警告:
WARNING in Circular dependency detected:
src\app\models\custom.form.ts -> src\app\models\forms.model.ts -> src\app\models\custom.form.ts
WARNING in Circular dependency detected:
src\app\models\forms.model.ts -> src\app\models\custom.form.ts -> src\app\models\forms.model.ts
在我的实际应用中,由于相同的模式,大约有 20-30 个警告。 我认为底层插件https://github.com/aackerman/circular-dependency-plugin 支持排除模式,但我不确定是否有办法通过 angular-cli 使用它。
【问题讨论】:
标签: angular warnings angular-cli circular-dependency