'ng-select' 不是已知元素
'ng-select' is not a known element
这是我的代码:
我想在我的表单上添加 https://github.com/ng-select/ng-select multi select 用于标签输入。
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 { }
我的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>
我的错误是:无法绑定到 'items',因为它不是 'ng-select' 的已知 属性 为什么?????
你能帮帮我吗?
非常感谢!
您必须在声明您的 ModalTestComponent
的模块中导入 NgSelectModule
,或者,如果您的 ComponentsModule
是一个包装器,您应该导入声明 [=12] 的模块=] 在其中;这样:
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 { }
作为替代方案,如@Narm 所说,您可以在 AppModule
中导入 NgSelectModule
,以便所有子模块都可以使用它。
First of all you should execute following command:
npm install --save @ng-select/ng-select
for more details click here
If you want to add your own module, you should use following pattern
import { YourModule } from 'path/to/your/module/without/@/symbol'
这是我的代码: 我想在我的表单上添加 https://github.com/ng-select/ng-select multi select 用于标签输入。
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 { }
我的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>
我的错误是:无法绑定到 'items',因为它不是 'ng-select' 的已知 属性 为什么?????
你能帮帮我吗? 非常感谢!
您必须在声明您的 ModalTestComponent
的模块中导入 NgSelectModule
,或者,如果您的 ComponentsModule
是一个包装器,您应该导入声明 [=12] 的模块=] 在其中;这样:
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 { }
作为替代方案,如@Narm 所说,您可以在 AppModule
中导入 NgSelectModule
,以便所有子模块都可以使用它。
First of all you should execute following command:
npm install --save @ng-select/ng-select
for more details click here
If you want to add your own module, you should use following pattern
import { YourModule } from 'path/to/your/module/without/@/symbol'