如果您使用的是 bootstrap4,那么 tether.js 已经是一个依赖项。这可能有效
使用 Angular-cli
首先,从 npm 安装 Bootstrap:
npm install bootstrap@next
Then add the needed script files to angular-cli.json --> scripts:
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../node_modules/tether/dist/js/tether.js",
"../node_modules/bootstrap/dist/js/bootstrap.js"
],
Finally add the Bootstrap CSS to the angular-cli.json --> styles array:
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.css",
"styles.css"`enter code here`
],
Restart ng serve if you're running it, and Bootstrap 4 should be working on your app.
对于 Webpack
如果你使用 webpack:
按照文档中的说明设置引导加载程序;
通过 npm 安装 tether.js;
将 tether.js 添加到 webpack ProvidePlugin 插件中:
plugins: [
<... your plugins here>,
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
"window.Tether": 'tether'
})
]
Bootstrap 4 不再使用标签 window.tether
Note that using Bootstrap 4.0.0-alpha.6,
Bootstrap 不再检查“window.Tether”,而是检查全局变量“Tether”,因此 webpack 配置变为
plugins: [
<... your plugins here>,
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
"Tether": 'tether'
})
]