Uncaught Error: Unexpected "MyComboBox" directive imported by "AppModule". Add @NgModule note
I have a custom component (MyComboBox) that has a kendo-combobox
combo box inside kendo-combobox
.
When I use my main module, compilation webpack
succeeds, but Chrome throws the following error:
Uncaught Error: Unexpected directive 'MyComboBox' imported by the module 'AppModule'. Please add a @NgModule annotation.
Here is my AppModule :
import { MyComboBox } from '@my/core/control/MyComboBox';
@NgModule({
declarations: [
AppComponent,
MyComboBox
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
DragulaModule,
MyComboBox,
CoreModule,
ComboBoxModule
],
entryComponents: [ MyComboBox ],
providers: [HelperService],
bootstrap: [AppComponent]
})
source to share
EDIT :
This error often occurs when we are wrong importing
, providing
or declaring
the angle modules
, services
, components
.
Make sure we should only
- imported
modules
and notcomponents
orservices
- declare
components
and notmodules
orservices
. - provide
services
and notcomponents
ormodules
.
Original answer:
You don't need to really import MyComboBox
into your app module. Since you've already exported it to CoreModule
. Therefore, I would suggest you remove MyComboBox
from the import array in AppModule
. Importing CoreModule
will give you a MyComboBox
component in AppModule
.
app.module.ts
@NgModule({
declarations: [
AppComponent,
MyComboBox
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
DragulaModule,
CoreModule
],
// viewProviders: [ DragulaService ],
providers: [HelperService],
bootstrap: [AppComponent]
})
Note: you cannot import the component freely as you do there. It must be contained in the module for import.
source to share
In my case, I was mistakenly listing a component in an array imports: []
, which of course expects modules, not components, and it is for this reason that Angular complained that it could not find a @NgModule
definition.
Instead, I needed to list the component in a list declarations: []
. :)
source to share