'ng-select' is not a known element

风流意气都作罢 提交于 2020-05-15 02:16:10

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/51446254/ng-select-is-not-a-known-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!