Runtime error ng-select-selection-model -

Viewed 2626

My purpose is to use this select

in my lazy load module I do:

imports: [
        CommonModule,
        FormsModule,    
        NgSelectModule        

    ],
    providers: []

The template:

<ng-select [items]="list" [bindLabel]="TIPE" bindValue="id" [(ngModel)]="tipe" (onChange)="changeValue($event)" >
            </ng-select>

When the user goes on this route, it prints in the console this error:

:

 Uncaught (in promise): NullInjectorError: R3InjectorError(AppModule)[InjectionToken ng-select-selection-model -> InjectionToken ng-select-selection-model -> InjectionToken ng-select-selection-model]: 
  NullInjectorError: No provider for InjectionToken ng-select-selection-model!
NullInjectorError: R3InjectorError(AppModule)[InjectionToken ng-select-selection-model -> InjectionToken ng-select-selection-model -> InjectionToken ng-select-selection-model]: 
  NullInjectorError: No provider for InjectionToken ng-select-selection-model!

I don't understand why,anyone can help me?

4 Answers

I had the same problem, I imported the NgSelectModule at both the main application module and the component module and it was fixed.

You might also want to look at this.

We had a different problem. We used @ng-select/ng-select": "3.7.2" and one of the third party component used the version 3.7.3.

After we updated to the same version the problem disappeared.

Do import NgSelectModule in your app.module.ts along with the component module.

I faced similar issue while running test case.

I resolved it by importing NgSelectModule under imports block.

If you are using NgSelectComponent in your code for some use-case/scenario purpose then you can also declare NgSelectComponent under declarations block if needed

TestBed.configureTestingModule({
        imports: [... , NgSelectModule],
        declarations: [MultiSelectCtrlComponent, NgSelectComponent],
        providers: []
    });

I hope it may help you or someone else!

Related