:建议的解决方案是正确的,我必须提到这一点
SharedModule
必须导入到使用DropDownDirective的子组件的父组件中才能工作。
我正在开发Angular 4应用程序,我想使用
共享模块
DirectivesModule
.我有一个组件X,它使用来自
定向模块
共享模块
应用程序/X.component.ts
import { SharedModule } from '../shared/shared.module';
<div class="col-xs-5 dropdown" appDropDown>
应用程序的结构如下:
root
-- X.component.ts
-- shared
-- shared.module.ts
-- directives
-- directives.module.ts
-- dropdown.directive.ts
我要做的是将DirectivesModule导入SharedModule,如下所示:
import { CommonModule } from '@angular/common';
import { DirectivesModule } from './directives/directives.module';
@NgModule({
imports: [
CommonModule
],
declarations: [
],
exports: [
DirectivesModule
]
})
export class SharedModule { }
DirectivesModule导入和导出DropDown指令如下:
import { DropDownDirective } from './dropdown.directive';
.....
exports: [
DropDownDirective,
]
共享模块