6
지시문이있어서 여러 모듈에서 사용하고 싶습니다. 각 모듈에서이를 선언하면 오류가 발생합니다. 따라서 공유 모듈에서이 모듈을 선언하고이 공유 모듈을 다른 모듈로 가져 오려고했습니다. 그러나 작동하지 않았습니다. 구성 요소 자체의 모듈에서 정확하게 선언 된 경우에만 작동합니다.Angular2 - 동일한 모듈에서 선언되지 않은 경우 지시문이 작동하지 않습니다.
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { GeneralDataService } from './general-data.service';
import {ModalDirective} from '../directives/modal.directive';
@NgModule({
imports: [
CommonModule
],
providers: [GeneralDataService],
declarations: [ModalDirective]
})
export class SharedModule { }
그리고 내가 원하는 모듈이 사용하는 ModalDirective
: 여기
SharedModule
입니다
MyComponent
에
export class MyComponent implements OnInit, AfterViewInit {
@ViewChild(ModalDirective) modal: ModalDirective;
...
}
modal
는입니다 :
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MyComponent } from './patient.component';
import {SharedModule} from '../shared/shared.module';
@NgModule({
imports: [
CommonModule,
SharedModule
],
providers: [ ],
declarations: [ MyComponent ]
})
export class MyModule { }
MyComponent
구성 요소에서 (ngAfterViewInit
에있는 경우) ModalDirective
이 MyModule
에 선언되지 않은 경우누구든지이 문제를 해결하는 방법을 알고 있습니까? 에서
에 대해 공유 모듈에 docs를 참조
export
해야합니다. 고맙습니다! –Thx 프레드릭! 내 지시어에는'TemplateRef'가 삽입되어 있습니다. 그러나 지시문을'NgModule.exports' 목록에 추가하면'No TemplateRef! '공급자가 없다는 오류가 발생합니다. 어떤 아이디어? – cosmozhang
@cosmozhang - 코드를 보지 않고도 알 수는 없지만이 스레드를 살펴보십시오. https://stackoverflow.com/questions/35932074/angular2-no-provider-for-templateref-ngif-templateref –