Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS code/Angular - Linter doesn't recognize components imported through shared module

So I have a shared module in my project where I'm importing, among other things, all of my Angular materials modules. My code builds and runs just fine. The issue is that in my html files, in vs code, I have the red squiggly lines under every angular materials component tag, with the error:

'mat-select' is not a known element:
1. If 'mat-select' is an Angular component, then verify that it is part of this module.
2. If 'mat-select' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.ng(0)

I've tried restarting the IDE. The message does go away if I import the material modules directly into my module, rather than through the shared module. Anyhow, here's my code:

shared.module.ts

...

@NgModule({
  imports: [
    CommonModule,
    ReactiveFormsModule,
    MatFormFieldModule,
    MatIconModule,
    MatInputModule,
    FlexLayoutModule,
    MatListModule,
    MatSelectModule,
    MatSidenavModule,
    MatToolbarModule
  ],
  exports:
  [
    ReactiveFormsModule,
    MatFormFieldModule,
    MatIconModule,
    MatInputModule,
    FlexLayoutModule,
    MatListModule,
    MatSelectModule,
    MatSidenavModule,
    MatToolbarModule
  ]
})
export class SharedModule { }

product.module.ts

...
@NgModule({
  declarations: [
    ProductComponent,
    ProductFormComponent,
    AddProductToStoreFormComponent,
    StorePickerComponent,
    StorePickerRootComponent,
    SizeFormComponent,
    CategoryPickerRootComponent,
    CategoryPickerComponent

  ],
  imports: [
    CommonModule,
    ProductRoutingModule,
    SharedModule
  ]
})
export class ProductModule { }

Thanks for looking.

like image 458
jmiles540 Avatar asked Nov 20 '25 22:11

jmiles540


1 Answers

Why are you exporting other modules in the export section? Export allows other modules to access components/pipes that declared your module. Not modules.

So in product.module.ts, import the MatFormFieldModule

like image 174
Sachila Ranawaka Avatar answered Nov 23 '25 11:11

Sachila Ranawaka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!