在angular2-rc中导入ng2-select.7 webpack



我使用webpack和npm安装了ng2-select,我已经安装了ng2-bootstrap并正常工作。但是当我导入ng2-select

时,我在控制台中得到以下错误

未捕获的错误:由模块'AppModule'导入的意外指令'SelectComponent'

这是我的app.module。ts 文件:

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';

import { Ng2BootstrapModule } from 'ng2-bootstrap/ng2-bootstrap';
import { SELECT_DIRECTIVES } from "ng2-select/ng2-select";
import { AppComponent }   from './app.component';
@NgModule({
  imports:      [ BrowserModule, Ng2BootstrapModule, SELECT_DIRECTIVES],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

app.component.ts

@Component({
    selector: 'search',
    styleUrls: ['app/assets/ng2-select.css'],
    templateUrl: '<ng-select [items]="items" placeholder="Country">
                </ng-select>'
})
export class AppComponent {
    public items: Array<string> = ['Austria', 'Belgium', 'Bulgaria', 'Croatia',
    'Czech Republic', 'Denmark', 'England', 'Egypt', 'Finland', 'France',
    'Germany', 'Greece', 'Hungary', 'Ireland', 'Italy', 'Netherlands',
    'Poland', 'Spain'];
}

如何解决这个问题?

你必须在AppModule中导入SelectModule才能使其工作,并删除SELECT_DIRECTIVES:

@NgModule({
  imports:      [ BrowserModule, Ng2BootstrapModule, SelectModule],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

最新更新