Marvin Ericson
Marvin Ericson

Reputation: 259

Import external Module in app.module.ts

I'm wondering about modules in Angular 4, If I have this module:

@NgModule({
  imports: [
    ...
    ...
  ],
  declarations: [
    OneComponent
  ],
})
export class OneModule { }

And in my app.modules.ts I use this module in the imports

@NgModule({
  imports: [
    ...
    OneModule
    ...
  ],
})
export class AppModule { }

Is that mean the OneComponent is declared in the App Module?

I'm facing a problem with TimeAgoModule package, If I put it in the OneModule imports, then the OneComponent should see the time, but it said that time is not defined, and If I move the OneComponent from OneModule declarations to AppModule declarations everything is fine. What exactly the idea?

Upvotes: 3

Views: 3170

Answers (1)

Shashank Vivek
Shashank Vivek

Reputation: 17494

You need to export OneComponent.

@NgModule({
  imports: [
    ...
    ...
  ],
  exports: [OneComponent],
  declarations: [
    OneComponent
  ],
})
export class OneModule { }

by exporting a component , you tell angular module that this specific component can be used outside the module and will be available for reuse in other modules.

Upvotes: 2

Related Questions