“ ng-select”不是已知元素

时间:2020-03-25 19:51:08

标签: angular ionic-framework angular-ngselect

我尝试使用select component来表示角度,但是在按照说明配置模块后,会抛出此错误。

错误

未捕获的错误:模板解析错误: “ ng-select”不是已知元素: 1.如果“ ng-select”是Angular组件,则请验证它是否属于此模块。 2.如果“ ng-select”是Web组件,则将“ CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“ @ NgModule.schemas”以禁止显示此消息。 [ERROR->] <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)

2 个答案:

答案 0 :(得分:0)

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

imports: [NgSelectModule]

答案 1 :(得分:0)

仅需重新启动开发环境并重新编译所有内容,便可以正常工作!

相关问题