Home > Enterprise >  Install Angular NgSelect module
Install Angular NgSelect module

Time:12-26

I was following this tutorial to install Ngselect module in an Angular app and got this error while serving app. I googled and couldn't find what is wrong here.

ERROR in Unexpected value 'NgSelectModule in D:/ku-site/ku-web/node_modules/@ng-select/ng-select/lib/ng-select.module.d.ts' imported by the module 'AppModule in D:/ku-site/ku-web/ku-web/src/app/app.module.ts'. Please add a @NgModule annotation.

app.module.ts

import { BrowserModule, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
import { APP_INITIALIZER, ErrorHandler, NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { NgSelectModule } from '@ng-select/ng-select';
import { FormsModule } from '@angular/forms';

@NgModule({
    declarations: [AppComponent],
    imports: [
        BrowserAnimationsModule,
        NgSelectModule,
        AppRoutingModule,
        FormsModule
    ],
    exports: [],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule {}

Edit: I missed the line import { APP_INITIALIZER, ErrorHandler, NgModule } from '@angular/core'; while simplifying the code for the question.

CodePudding user response:

For Angular 9, you need to use version 4.x. Check the documentation here -

CodePudding user response:

You missed to import ngModule in your app.module.ts, so it doesn't uderstand the @NgModule({ decoration. Missed the import { AppComponent } from './app.component'; as well.

// app.module.ts
...
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
...

@NgModule({
  declarations: [
    AppComponent
  ],

CodePudding user response:

You didn't import NgModule & AppComponent.

import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
  • Related