【问题标题】:‘ng-select’ is not a known element“ng-select”不是已知元素
【发布时间】:2020-03-25 19:51:08
【问题描述】:

我正在尝试将select component 用于角度,但在我按照说明配置模块后,抛出此错误。

错误

未捕获的错误:模板解析错误: 'ng-select' 不是已知元素: 1. 如果 'ng-select' 是一个 Angular 组件,那么验证它是这个模块的一部分。 2. 如果 'ng-select' 是一个 Web 组件,则将 'CUSTOM_ELEMENTS_SCHEMA' 添加到此组件的 '@NgModule.schemas' 以禁止显示此消息。 [错误->]<ng-select placeholder="Select city"></ng-select>

我的 app.module.ts 是怎样的:

...
import { NgSelectModule } from '@ng-select/ng-select';
import { FormsModule } from '@angular/forms';

@NgModule({
    declarations: [AppComponent],
    entryComponents: [...],
    imports: [..., NgSelectModule, FormsModule],
    providers: [
        ...
    ],
    bootstrap: [AppComponent]
})
export class AppModule {}

我尝试遵循this post 的解决方案,它具有相同的错误,但即使我这样做,我也会收到此错误。我还尝试将NgSelectModule 导入并添加到我的页面模块,但没有任何变化。我什至尝试将模块添加到app-routing.module.ts,因为我读到有人提到过,但也没有用。

其他信息:

Ionic CLI                     : 5.4.16 
Ionic Framework               : @ionic/angular 4.11.7
@angular-devkit/build-angular : 0.801.2
@angular-devkit/schematics    : 8.1.3
@angular/cli                  : 8.1.3
@ionic/angular-toolkit        : 2.0.0
Cordova CLI                   : 9.0.0 (cordova-lib@9.0.1)

【问题讨论】:

    标签: angular ionic-framework angular-ngselect


    【解决方案1】:

    您是否仅在 AppModule 中使用 Ng-Select?因为如果你要在另一个中使用它,你也应该声明 NgSelectModule。

    imports: [NgSelectModule]

    【讨论】:

    • 据我所知,在 AppModule 中导入应该适用于应用程序的所有其他页面。尽管如此,我尝试在我想使用的页面模块(page.module.ts)中导入NgSelectModule,但错误仍然存​​在。
    【解决方案2】:

    简单地重启开发环境并重新编译一切后,它工作了!

    【讨论】:

      猜你喜欢
      • 2018-12-28
      • 2017-06-13
      • 1970-01-01
      • 1970-01-01
      • 2017-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多