'ng-select' 不是已知元素 [英] 'ng-select' is not a known element
问题描述
这是我的代码:我想在我的表单中添加 https://github.com/ng-select/ng-select 多选标签输入.
components.module.ts:
import { NgModule } from '@angular/core';从'@angular/common'导入{CommonModule};从'@angular/common/http'导入{HttpClientModule};从@angular/forms"导入 { FormsModule, ReactiveFormsModule };从 '@ng-select/ng-select' 导入 { NgSelectModule };@NgModule({进口:[通用模块,HttpClient 模块,表单模块,反应形式模块,吴选择模块,]})导出类 ComponentsModule { }
我的modaltest.component.html
<label class="control-label"><strong>古斯蒂:</strong>标签>[错误] ---><ng-select [items]="testitems" [hideSelected]="true" multiple="true" bindLabel="text1"></ng-select>
我的错误是:无法绑定到items",因为它不是ng-select"的已知属性,为什么????
你能帮我吗?非常感谢!
您必须在声明您的 ModalTestComponent
的模块中导入 NgSelectModule
,或者,如果您的 ComponentsModule
是一个包装器,你应该在其中导入声明 ModalTestComponent
的模块;这样:
import { NgModule } from '@angular/core';从'@angular/common'导入{CommonModule};从'@angular/common/http'导入{HttpClientModule};从@angular/forms"导入 { FormsModule, ReactiveFormsModule };从 '@ng-select/ng-select' 导入 { NgSelectModule };//添加这一行从路径/到/模块"导入 { ModuleThatDeclaresModalTest }@NgModule({进口:[通用模块,HttpClient 模块,表单模块,反应形式模块,吴选择模块,//还有这一行ModuleThatDeclaresModalTest]})导出类 ComponentsModule { }
<小时>
作为替代方案,正如@Narm 所说,您可以在 AppModule
中导入 NgSelectModule
,以便所有子模块都可以使用它.
this is my code: I want to add on my form https://github.com/ng-select/ng-select multi select for tags input.
components.module.ts:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HttpClientModule } from '@angular/common/http';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { NgSelectModule } from '@ng-select/ng-select';
@NgModule({
imports: [
CommonModule,
HttpClientModule,
FormsModule,
ReactiveFormsModule,
NgSelectModule,
]
})
export class ComponentsModule { }
my modaltest.component.html
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<label class="control-label">
<strong>Gusti:</strong>
</label>
[ERROR] ---> <ng-select [items]="testitems" [hideSelected]="true" multiple="true" bindLabel="text1"></ng-select>
</div>
My error is: Can't bind to 'items' since it isn't a known property of 'ng-select' Why?????
Can you help me? Thank's a lot!
You have to import the NgSelectModule
in the module that declares your ModalTestComponent
, or, if your ComponentsModule
is a wrapper, you should import the module that declares ModalTestComponent
in it; this way:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HttpClientModule } from '@angular/common/http';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { NgSelectModule } from '@ng-select/ng-select';
// add this line
import { ModuleThatDeclaresModalTest } from 'path/to/module'
@NgModule({
imports: [
CommonModule,
HttpClientModule,
FormsModule,
ReactiveFormsModule,
NgSelectModule,
// and this line
ModuleThatDeclaresModalTest
]
})
export class ComponentsModule { }
As an alternative, as @Narm said, you can import NgSelectModule
in your AppModule
, so that all children modules can use it.
这篇关于'ng-select' 不是已知元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!