3

I want to use product-carousel.module.ts in home component. My product-carousel module looks like

const COMPONENTS = [
  ProductBlockComponent,
  ProductCarouselComponent,
  ProductCarouselContainerComponent
];

@NgModule({
imports: [
  CommonModule,
  RouterModule
],
declarations: COMPONENTS,
providers: [],
exports: COMPONENTS
})
export class ProductCarouselContainerModule {}

Than I register it in home.module.ts

@NgModule({
imports: [
  ProductCarouselContainerModule,
  CommonModule,
  FormsModule,
  ProductCarouselContainerModule,
  ComponentsModule,
  ]),
 ],
 declarations: [
  HomeContainer
 ],
 providers: [
   ProductApiService
 ]
})
export class HomeModule {} 

I want to use ProductCarouselContainerComponent. It has selector 'offer-carousel'. In home component I using it like this

<div class="container-fluid currently-funding">
   <product-carousel></product-carousel>
</div>

And as result I have

Error: Template parse errors: 'Product-carousel' is not a known element: 1. If 'offer-carousel' is an Angular component, then verify that it is part of this module. 2. If 'Product-carousel' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA

What I missed?

20
  • Its confusing. home.module.ts is component. Right? If yes please name it as home.component.ts. For better understanding. Commented Sep 26, 2017 at 13:20
  • @TavishAggarwal home.module.ts - it's a module, which contains some components. And I want to use one from it. It's named OfferCarouselContainerComponent and has selector "offer-carousel" Commented Sep 26, 2017 at 13:26
  • okay! Looks ok to me.. let me see if I can help you out Commented Sep 26, 2017 at 13:44
  • @TavishAggarwal it will be cool. Thank you, buddy Commented Sep 26, 2017 at 13:53
  • Be careful to not import twice your OfferCarouselContainerModule in your HomeModule, but appart from that it looks Ok. In your 3 components, make sure that one has the correct offer-carousel selector. It should work. Sending us a GitHub link would be better in that case because a lof of things could cause this issue which is hard to pinpoint Commented Sep 26, 2017 at 14:44

1 Answer 1

1

The error is actually displayed in your screenshot. The issue is that the HomeComponent is declared in the ComponentsModule and not in the HomeModule.

Changing this in your ComponentsModule will make it work (well there is an async pipe error but that's something else obviously) :

app/home/components/index.ts :

import { OfferCarouselModule } from './../../offer/offer-carousel.module';

@NgModule({
  imports: [
    CarouselModule.forRoot(),
    CommonModule,
    ReactiveFormsModule,
    RouterModule,
    SlickModule,
    OfferCarouselModule
  ],
  declarations: COMPONENTS,
  exports: COMPONENTS,
})
export class ComponentsModule { }
Sign up to request clarification or add additional context in comments.

4 Comments

But it's still a bizarre way of architecture, because you have Home containers, with HomeComponents, and barrels used as modules, etc... This requires a bit of cleanup I believe...
Sorry, didn't see your comment
No problem mate it's fine
Yes, the project is a mess tbh :D

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.