2017-11-24 22 views
1

https://github.com/angular/angular-cli/pull/6813 순환 종속성에 대한 경고가 추가되었으며 "showCircularDependencies": false을 사용하여 모든 경고를 해제 할 수 있음을 알고 있습니다. 그러나 순환 의존성 경고를 계속 유지하려고합니다. 아래의 사용 사례를 해결할 수있는 패턴이 있습니까? 아니면 특정 파일에 순환 종속성 플러그인을 사용하지 않도록 설정하는 방법이 있습니까?순환 종속성의 경고 - Angular 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은 제외 패턴을 지원한다고 생각하지만, 이것이 앵글 -CHI를 통해 이것을 사용하는 방법인지는 확실하지 않습니다.

+0

확인 https://github.com/angular/angular-cli/issues/7705 –

답변

1

문제는 분명하다 : 당신은 custom.model.ts을 사용하는

CircularDependencies라고하고이 좋지 않다

custom.model.ts로도 custom.form.ts, custom.form.ts로.

솔루션 :

그냥 당신이 동일한 파일에 forms.model.ts 및 custom.form.ts의 코드를 가질 수 custom.model.ts

+0

아 죄송합니다.이 SO 질문을 만들 때 실수로 가져 왔습니다. 나는 원래 질문에서 그 라인을 편집했다. 이 경우 가져 오기 제거가 도움이되지 않습니다. 순환 종속성은 새 Forms() 및 새 CustomForms()에 대한 호출로 인해 발생합니다. –

0

에서 import { CustomForm } from './custom.form';를 제거하고 그 순환 종속성을 제거합니다.