'ng-select'不是一个已知的元素

时间:2018-07-20 15:51:48

标签: angular jquery-select2 angular6

这是我的代码: 我想在表单https://github.com/ng-select/ng-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>

我的错误是:无法绑定到“项目”,因为它不是“ ng-select”的已知属性。

你能帮我吗? 非常感谢!

2 个答案:

答案 0 :(得分:3)

您必须在声明您的NgSelectModule的模块中导入ModalTestComponent,或者,如果您的ComponentsModule是包装器,则应该导入声明ModalTestComponent的模块在里面;这样:

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所说,您可以在NgSelectModule中导入AppModule,以便所有子模块都可以使用它。

答案 1 :(得分:0)

首先,您应该执行以下命令:

npm install --save @ng-select/ng-select

了解更多详情,click here


如果要添加自己的模块,则应使用以下模式

import { YourModule } from 'path/to/your/module/without/@/symbol'
相关问题