2017-11-24 14 views
1

https://github.com/angular/angular-cli/pull/6813循環依存関係の警告が追加されました。"showCircularDependencies":falseを使用してすべての警告を無効にすることができます。しかし、私はむしろ循環的な依存性の警告を保持しています。 以下のユースケースを修正するパターンがありますか、特定のファイルに対して循環依存プラグインを特に無効にする方法がありますか?警告:循環依存関係が検出されました - 角度Cli

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[];  
} 

カスタム:私は3つのファイルを持っている場合

最も単純なシナリオがあります。 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がパターンを除外することをサポートしていると思うが、私は角度のcliを介してこれを使用する方法はありません。

+0

これを確認してくださいhttps://github.com/angular/angular-cli/issues/7705 –

答えて

1

問題がクリアされている:あなたはcustom.model.tsを使用している

これはCircularDependenciesと呼ばれ、それは良くない

custom.model.tsにもcustom.form.tscustom.form.tsに。

ソリューション:

だけでは、同じファイル内forms.model.tsとcustom.form.tsのコードを持つことができますcustom.model.ts

+0

申し訳ありません、このSOの質問を作成すると、そのインポートは偶然でした。私は元の質問からその行を編集しました。この場合、インポートの削除は役に立ちません。循環依存関係は、新しいForms()および新しいCustomForm()への呼び出しによって発生します。 –

0

からimport { CustomForm } from './custom.form';を削除し、それが循環依存関係を削除します。

関連する問題