无法使用bootstrap-multiselect(http://davidstutz.de/bootstrap-multiselect)来使用Angular2 +。到目前为止,我可以看到一切都安装正确:
packages.json
:
"dependencies": {
(...)
"bootstrap": "^4.1.3",
"bootstrap-multiselect": "^0.9.13-1",
"jquery": "^3.3.1",
}
angular.json
:
"styles": [
"./node_modules/bootstrap/scss/bootstrap.scss",
"./node_modules/bootstrap-multiselect/dist/css/bootstrap-multiselect.css",
"src/styles.css"
],
"scripts": [
"./node_modules/jquery/dist/jquery.js",
"./node_modules/bootstrap/dist/js/bootstrap.js",
"./node_modules/bootstrap-multiselect/dist/js/bootstrap-multiselect.js",
]
但是当我在浏览器中加载应用程序时,我收到一个错误:
TypeError: $ is undefined
./node_modules/bootstrap-multiselect/dist/js/bootstrap-multiselect.js/<
bootstrap-multiselect.js:1388
./node_modules/bootstrap-multiselect/dist/js/bootstrap-multiselect.js
bootstrap-multiselect.js:44
__webpack_require__
./src/app/tasks/tasks.component.ts
__webpack_require__
./src/app/app.module.ts
__webpack_require__
./src/main.ts
__webpack_require__
[0]
__webpack_require__
checkDeferredModules
webpackJsonpCallback
我的猜测是webpack采用脚本以错误的顺序创建bundle。它应该在bootstrap-multiselect之前放置jQuery,而是把它放在另一个方向。
它确实可能是一个webpack问题。根据我的经验,使用以某种方式包装的包装总是更容易,以便它可以被角度使用。
有一个名为angular2dropdown-multiselect的包。
您是否可以选择使用此软件包,或者是bootstrap-multiselect对您的用例的硬性要求?