Search code examples
angulartypescriptselectangular-ngselect

Install Angular NgSelect module


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.


Solution

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