【问题标题】:Runtime error ng-select-selection-model -运行时错误 ng-select-selection-model -
【发布时间】:2021-02-24 11:14:27
【问题描述】:

我的目的是使用这个select

在我的延迟加载模块中:

imports: [
        CommonModule,
        FormsModule,    
        NgSelectModule        

    ],
    providers: []

模板:

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

当用户走这条路线时,它会在控制台中打印这个错误:

 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!

我不明白为什么,有人可以帮助我吗?

【问题讨论】:

  • 我们有同样的问题,我们还没有解决方案。

标签: angular select package.json angular-ngselect


【解决方案1】:

我遇到了同样的问题,我在主应用程序模块和组件模块都导入了NgSelectModule,它已经修复了。

您可能还想查看this

【讨论】:

  • 这个答案对我有帮助。我有一个父子相关组件,我在父子组件中加载子组件。当我在父级中添加导入语句时,我的组件加载正常。
【解决方案2】:

我们遇到了不同的问题。我们使用了 @ng-select/ng-select": "3.7.2" 并且第三方组件之一使用了 3.7.3 版本。

我们更新到相同版本后,问题就消失了。

【讨论】:

    【解决方案3】:

    我在运行测试用例时遇到了类似的问题。

    我通过在imports 块下导入NgSelectModule 解决了这个问题。

    如果您在代码中使用 NgSelectComponent 用于某些用例/场景目的,那么您也可以根据需要在 declarations 块下声明 NgSelectComponent

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

    我希望它可以帮助你或其他人!

    【讨论】:

      【解决方案4】:

      在您的app.module.ts 中导入NgSelectModule 以及组件模块。

      【讨论】:

        猜你喜欢
        • 2020-04-04
        • 1970-01-01
        • 2015-07-14
        • 2013-06-06
        • 1970-01-01
        • 1970-01-01
        • 2019-08-25
        • 1970-01-01
        • 2014-05-28
        相关资源
        最近更新 更多