我在AngularJS项目中使用基于jQuery的select2组件.我和这里的人有类似的问题:https://github.com/fronteed/icheck/issues/322,并使用那里的建议解决了它.准确地说,我TypeError: $(...).select2 is not a function在没有使用该建议时收到错误.
即我在Webpack的配置中添加了下一行@angular/cli/models/webpack-configs/common.js.
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
]
Run Code Online (Sandbox Code Playgroud)
它是在angular/cli中启用jQuery的最佳方法吗?
我不认为在https://github.com/angular/angular-cli/wiki/stories-global-lib中做同样的事情是正确的,因为
a)webpack捆绑jQuery而无需在脚本中指定它
b)TypeError: $(...).select2 is not a function当你按照故事中所描述的那样包含它时,它仍会抛出错误.