在angular2 rc.7网页中导入ng2 select
使用webpack,我使用npm安装了ng2 select,我安装了ng2引导程序,运行良好。但是当我导入ng2 select时,我的控制台中出现了以下错误 未捕获错误:模块“AppModule”导入了意外的指令“SelectComponent” 这是我的app.module.ts文件:在angular2 rc.7网页中导入ng2 select,angular,webpack,ng2-bootstrap,Angular,Webpack,Ng2 Bootstrap,使用webpack,我使用npm安装了ng2 select,我安装了ng2引导程序,运行良好。但是当我导入ng2 select时,我的控制台中出现了以下错误 未捕获错误:模块“AppModule”导入了意外的指令“SelectComponent” 这是我的app.module.ts文件: import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser';
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 { }
应用程序组件.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'];
}
@组件({
选择器:“搜索”,
样式URL:['app/assets/ng2 select.css'],
templateUrl:'
'
})
导出类AppComponent{
公共项目:数组=[“奥地利”、“比利时”、“保加利亚”、“克罗地亚”,
“捷克共和国”、“丹麦”、“英国”、“埃及”、“芬兰”、“法国”,
“德国”、“希腊”、“匈牙利”、“爱尔兰”、“意大利”、“荷兰”,
“波兰”、“西班牙”];
}
任何解决此问题的方法。您必须在AppModule中导入
选择模块
,以使其正常工作,并删除选择指令
:
@NgModule({
imports: [ BrowserModule, Ng2BootstrapModule, SelectModule],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
有关更多详细信息,请参阅。我使用的是ng2 select()而不是angular2 select。问题是此库使用的是angular2 rc1。也许在声明中放入
SELECT\u指令可以解决您的问题,否则您将不得不等待模块。在RC7中使用SelectModule
。谢谢