警告检测到循环依赖-Angular Cli [英] WARNING in Circular dependency detected - Angular Cli

查看:65
本文介绍了警告检测到循环依赖-Angular Cli的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://github.com/angular/angular-cli/pull/6813 添加了有关循环依赖项的警告,我知道可以使用"showCircularDependencies":false 关闭所有警告.但是我宁愿保持循环依赖警告. 是否有一种模式可以让我修复以下用例,或者是否有办法专门禁用特定文件上的循环依赖插件?

https://github.com/angular/angular-cli/pull/6813 Added warnings for circular dependencies, and I know I can turn off all warnings using "showCircularDependencies": false. But I would rather keep the circular dependency warnings on. Is there a pattern that will let me fix the use case below, or is there a way to specifically disable the circular dependency plugin on a particular file?

最简单的情况是如果我有3个文件:

The simplest scenario is if I have 3 files:

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使用它.

In my actual app there are about 20-30 warnings because of this same pattern. I think the underlying plugin https://github.com/aackerman/circular-dependency-plugin supports exclude patterns, but i'm not sure if theres a way to use this via the angular-cli.

推荐答案

问题很明显:

您在custom.form.ts

以及custom.form.tscustom.model.ts

这叫做CircularDependencies,这不好.

解决方案:

只需从custom.model.ts

这篇关于警告检测到循环依赖-Angular Cli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆