2017-09-12 5 views
0

componentsapp 두 개의 npm 패키지가 있습니다. components 여러 앱에서 사용할 재사용 가능한 구성 요소가 포함되어 있다고 가정합니다. 일부 구성 요소가 NgModule에서 잘 작동하기를 바랍니다.구성 요소가 외부 모듈에있는 경우 각도 4에 값 ​​접근자가 표시되지 않습니다.

나는 그렇게 정의 된 시험 제어있어 : TestControlComponent 모든 인터페이스 요소하지만 조합 (나는 간결을 생략)가

export const VALUE_ACCESSOR: any = { 
    provide: NG_VALUE_ACCESSOR, 
    useExisting: forwardRef(() => TestControlComponent), 
    multi: true 
}; 

@Component({ 
    selector: 'test-control', 
    templateUrl: './test-control.component.html', 
    styleUrls: ['./test-control.component.scss'], 
    providers: [ VALUE_ACCESSOR ] 
}) 
export class TestControlComponent implements OnInit, ControlValueAccessor { ... } 

/// 구성 요소 패키지

합니다.

그리고 모듈에서 그 같은 수출되고 있습니다 :

@NgModule({ 
    imports: [ 
    ], 
    declarations: [ 
    TestControlComponent 
    ], 
    exports: [ 
    TestControlComponent 
    ] 
}) 
export class ComponentModule {} 

그리고 그것과 같이 소비 :

// APP 패키지

app.module.ts :

import { ComponentModule } from '@company/components'; 
import { FormsModule } form '@angular/forms' 

@NgModule({ 
    imports: [ FormsModule, ComponentModule ], 
    ... 
}) 

그리고 app.module.ts에 선언 된 일부 구성 요소의 사용법 :

이로 인해 앱이 컴파일되지만 런타임에 core.es5.js:1020 ERROR Error: Uncaught (in promise): Error: No value accessor for form control with name: 'test' Error: No value accessor for form control with name: 'test'이 발생하고 가져온 컨트롤이 작동하지 않습니다. 컨트롤을 앱 패키지에 복사하고 app.module.ts에 선언하면 모든 것이 작동합니다.

가치 접근자가 있습니다. 왜 Angular가 이것을 인식하지 못하는지 알고 있습니까?

답변

0

FormsModuleimports: [] 배열 ComponentModule 선언으로 가져올 수 있습니까? ComponentModule의 일부인 <test-control></test-control> 태그에 사용 된 ngModel 속성에 작동하도록 가져온 필수 모듈이 없습니다. (실제로 코멘트로 추가 할 예정 이었지만 아직 알려주지 않았습니다.)

+0

실제로 @ Angular/Common뿐만 아니라 가져온 것입니다. 예제를 더 짧게 만들었습니다 (ReactiveFormsModule도 임포트 중입니다). –

+0

그래, 관련 구성 요소 섹션을 완전히 보여 주시겠습니까? 실제로 문제 해결에 도움이됩니다. 또는 큰 덩어리가 될 것입니다! – amal