在Angular 6中使用ng2-select2
我不明白如何在我的Angular 6应用程序中使用。我怀疑我没有正确安装必备软件Select2,因为当我尝试加载我的应用程序时,我在浏览器的开发者控制台中遇到以下错误:在Angular 6中使用ng2-select2,angular,jquery-select2,Angular,Jquery Select2,我不明白如何在我的Angular 6应用程序中使用。我怀疑我没有正确安装必备软件Select2,因为当我尝试加载我的应用程序时,我在浏览器的开发者控制台中遇到以下错误: Uncaught Error: Unexpected module 'Select2Module' declared by the module 'AppModule'. Please add a @Pipe/@Directive/@Component annotation. 下面是我安装Select2必备软件的步骤。我使用了
Uncaught Error: Unexpected module 'Select2Module' declared by the module 'AppModule'. Please add a @Pipe/@Directive/@Component annotation.
下面是我安装Select2必备软件的步骤。我使用了此处讨论的手动安装选项,但没有遵循说明:
将编译后的文件包括在页面中:
我用以下行更新了我的angular.json
文件:
"styles": [
...
"select2-4.0.5/dist/css/select2.min.css"
],
"scripts": [
...
"select2-4.0.5/dist/js/select2.full.js"
]
我很确定我的路径是正确的,因为如果我使用了错误的路径
npm install
ng serve ...
。。。我用来启动ng服务器的命令会抱怨它可能会抱怨它们无法处理select2.full.js
和select2.min.css
文件
我还更新了app.modules.ts文件。我添加了这个导入
import { Select2Module } from 'ng2-select2';
这是我的@NgModule
声明:
Select2Module
Select2Module应添加到导入数组而不是声明数组 导入选择2模块至@NgModule:
imports: [
Select2Module
]
啊!是的,它修好了。谢谢