首页 文章

'ng-select'不是已知元素

提问于
浏览
1

这是我的代码:我想在我的表单上添加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>

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

你能帮助我吗?非常感谢!

1 回答

  • 2

    您必须在声明 ModalTestComponent 的模块中导入 NgSelectModule ,或者,如果 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所说,您可以在 AppModule 中导入 NgSelectModule ,以便所有子模块都可以使用它 .

相关问题