且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使模块在Angular应用程序中全局可用

更新时间:2023-11-22 17:23:22

只需创建一个SharedModule,然后将ClickOutsideModule添加到它的importsexports数组中.像这样:

Just create a SharedModule, add the ClickOutsideModule to the imports and exports array of it. Something like this:

import { NgModule } from '@angular/core';
import { ClickOutsideModule } from "ng-click-outside";

@NgModule({ 
  imports: [
    ClickOutsideModule,
    ...
  ],  
  exports: [
    ClickOutsideModule,
    ...
  ],
})
export class SharedModule {}

,然后在要访问ClickOutsideModule模块的任何位置导入SharedModule.举例来说,如果您希望在AppModule中使用它,请按以下步骤操作:

And then import the SharedModule whereever you want to have access to the ClickOutsideModule module. Say for eg, if you want it in the AppModule, here's how you'll do it:

...
import { SharedModule } from './shared/shared.module';

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

export class AppModule { }

您可以对PopupModule做同样的事情:

You can do the same for PopupModule:

...
import { SharedModule } from './shared/shared.module';

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

export class PopupModule { }