【问题标题】:Install Angular NgSelect module安装 Angular NgSelect 模块
【发布时间】:2022-01-25 18:55:29
【问题描述】:

我正在关注此tutorial 在 Angular 应用程序中安装 Ngselect 模块,并在提供应用程序时出现此错误。我用谷歌搜索并找不到这里有什么问题。

模块“AppModule”导入的意外值“D:/ku-site/ku-web/node_modules/@ng-select/ng-select/lib/ng-select.module.d.ts”中的错误值“NgSelectModule”在 D:/ku-site/ku-web/ku-web/src/app/app.module.ts'。请添加@NgModule 注解。

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 {}

编辑:我在简化问题代码时错过了import { APP_INITIALIZER, ErrorHandler, NgModule } from '@angular/core'; 行。

【问题讨论】:

  • 导入NgModule后现在解决了吗?
  • No.. 仍然抛出同样的错误。
  • 你是否也错过了 import { AppComponent } from './app.component'; 这行?
  • 您使用的 angular 和 ng-select 版本是什么?
  • Angular: 9.1.3"@ng-select/ng-select": "^8.1.1"

标签: angular typescript select angular-ngselect


【解决方案1】:

您没有导入 NgModuleAppComponent

import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';

【讨论】:

  • 抱歉,我已经在导入 ngModule。在这里编辑代码时错过了。
  • 仍然出现错误?
  • 是的,仍然有错误。
  • 是相同的错误还是不同的错误?
  • 同样的错误。 ngModule 导入已经存在。
【解决方案2】:

您错过了在 app.module.ts 中导入 ngModule,因此它不理解 @NgModule({ 装饰。 也错过了 import { AppComponent } from './app.component';

// app.module.ts
...
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
...

@NgModule({
  declarations: [
    AppComponent
  ],

【讨论】:

  • 我仍然收到错误消息。我已经编辑了问题
  • 你是否也错过了 import { AppComponent } from './app.component'; 行?
  • 抱歉代码太大了。所以我在简化时错过了它。已经在实际代码中导入了
  • 为了获得更好的帮助,如果您能在stackblizt沙箱中重现导致相同错误的简化代码应该会更好。
【解决方案3】:

对于 Angular 9,您需要使用 4.x 版本。查看文档here -

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-23
    • 2016-10-09
    • 1970-01-01
    • 2020-10-16
    • 2018-02-23
    • 2016-02-20
    • 2017-07-24
    • 2021-11-25
    相关资源
    最近更新 更多