Runtime error ng-select-selection-model -
Asked Answered
Q

5

5

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?

Quartan answered 12/11, 2020 at 12:38 Comment(1)
We have the same problem and we don't have a solution yet.Meza
S
9

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.

Stilla answered 17/11, 2020 at 5:22 Comment(1)
This answer helped me. I had a parent-child related components where I was loading the child component within parent. When I added the import statement in the parent, my component loaded fine.Observant
A
2

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

Arson answered 18/10, 2021 at 6:33 Comment(0)
M
1

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.

Meza answered 17/11, 2020 at 11:11 Comment(0)
S
0

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!

Sulky answered 21/5, 2021 at 6:57 Comment(0)
B
0

Only add NgSelectModule to app.module.ts and it works all across your app. This module doesn't work properly in a modal for example, because of it lazy loading.

Branching answered 28/10, 2022 at 4:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.