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?

adsds
  • 123
  • 1
  • 12

5 Answers5

8

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.

Gimmly
  • 443
  • 1
  • 6
  • 15
  • 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. – Chetan Oswal Jul 22 '21 at 15:56
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.

Zsolt Balogh
  • 595
  • 1
  • 5
  • 12
1

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

umunBeing
  • 514
  • 1
  • 5
  • 15
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!

Ambuj Khanna
  • 1,131
  • 3
  • 12
  • 32
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.