1

I want to use one component in another two components like that:

<jhi-articles-list-component [active]="true"></jhi-articles-list-component>

so i created some shared module and export that component like this:

@NgModule({
    exports: [ArticlesListComponent]
})
export class ArticlesListModule {}

And then im imported that module in modules that i want to use that component which causes the error:

Can't export directive ArticlesListComponent from ArticlesListModule as it was neither declared nor imported!

3 Answers 3

2

You should add declarations :

@NgModule({
    declarations: [ArticlesListComponent],
    exports: [ArticlesListComponent]
})
export class ArticlesListModule {}
Sign up to request clarification or add additional context in comments.

4 Comments

I get multiple template parse errors now, it works perfectly fine when i add that component in one of that modules like this: declarations: [HomeComponent ArticlesListComponent],
What i meant was, import the ArticlesListModule in your module where you have to use it and then ArticlesListComponent can be used there. what error do you get?
i'm doing exactly what you said, i get that error: ibb.co/P4BfCCH
@MaciejOstaszewski in your ArticlesListModule try to : import { CommonModule } from '@angular/common'; and then add CommonModule to another array within @NgModule : imports: [CommonModule ]
0

Your component (used at multiple places) should be declared and exported from it's module.

This will make it available in other modules and can be used once component's module (in this case: ArticlesListModule ) is imported:

    @NgModule({
       declarations: [ArticlesListComponent],
       exports: [ArticlesListComponent]
    })
    export class ArticlesListModule {}

3 Comments

@MaciejOstaszewski Did you import ArticlesListModule and add it to imports array of @NgModule of the module where you are using the component?
Yes i did it as you say
The error is with the way you use ngSwitch in HTML. ngSwitch can't be on a <template> element, only on real elements like <div> Only ngSwitchCase can be applied to <template> elements. Check this out: stackoverflow.com/a/41085168/9386929
0

I add some imports to that shared module like CommonModule and it works now.

@NgModule({
   imports: [ArticleSharingAppSharedLibsModule, ArticleSharingAppSharedCommonModule, 
   ArticleSharingAppAppRoutingModule],
   declarations: [ArticlesListComponent],
   exports: [ArticlesListComponent],
   schemas: [CUSTOM_ELEMENTS_SCHEMA],

})
export class ArticlesListModule {}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.