代码之家  ›  专栏  ›  技术社区  ›  Petya Naumova

如何从内部使用部分指令的组件访问DirectivesModule?

  •  1
  • Petya Naumova  · 技术社区  · 8 年前

    :建议的解决方案是正确的,我必须提到这一点 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,
       ]
    

    共享模块

    1 回复  |  直到 8 年前
        1
  •  1
  •   Dean Chalk    8 年前

    添加 DirectivesModule

    @NgModule({
      imports: [
        CommonModule,
        DirectivesModule
      ], 
    ......
    
    推荐文章