3

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?

0

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.