'ng-select'不是一个已知的元素 [英] 'ng-select' is not a known element

查看:91
本文介绍了'ng-select'不是一个已知的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码: 我想在表单上添加 https://github.com/ng-select/ng-select 多次选择标签输入.

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:

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

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>

我的错误是:无法绑定到项目",因为它不是"ng-select"的已知属性,为什么????

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!

推荐答案

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

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 { }


作为替代方案,如@Narm所说,您可以在AppModule中导入NgSelectModule,以便所有子模块都可以使用它.


As an alternative, as @Narm said, you can import NgSelectModule in your AppModule, so that all children modules can use it.

这篇关于'ng-select'不是一个已知的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆