[英]How to solve the error of popper.js in console in Angular2
i installed angular ng-select, and while running the app i am getting error as 我安装了angular ng-select,并且在运行应用程序时出现错误
Uncaught ReferenceError: Popper is not defined
at scripts.bundle.js:12
Can anyone help to solve this error. 任何人都可以帮助解决此错误。
anuglar-cli.json: anuglar-cli.json:
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css",
"../node_modules/bootstrap/dist/css/bootstrap.min.css"
],
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/bootstrap/dist/js/bootstrap.min.js"
],
Since you are using angular-cli and didn't add the dependency to you anuglar-cli.json , meaning the reference doesn't get compiled into your project. 由于您使用的是angular-cli,并且没有向您添加依赖项anuglar-cli.json ,这意味着该引用不会被编译到您的项目中。 So you are able to use it the package. 因此,您可以使用它的包。
First you need to add the package to your package.json file. 首先,您需要将包添加到package.json文件中。
{
"name": "appname",
"version": "0.0.0",
},
"scripts": {
},
"private": true,
"dependencies": {
},
"devDependencies": {
"popper.js": "^1.12.5",
}
}
Or simple run 还是简单的运行
npm install popper.js --save-dev
After that step you need to take a look at your angular-cli.json file. 完成该步骤后,您需要查看您的angular-cli.json文件。 Look at the following code and take a closer look at the "scripts" section: 查看以下代码,并仔细查看“脚本”部分:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "appname"
},
"apps": [
{
"root": "src",
"outDir": "server/public",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.scss",
"../node_modules/bootstrap/dist/css/bootstrap.css"
],
"scripts": [
"../node_modules/jquery/dist/jquery.slim.min.js",
"../node_modules/popper.js/dist/umd/popper.min.js",
"../node_modules/bootstrap/dist/js/bootstrap.min.js"
]
}
]
}
You can see that I added the path from the angular-cli.json to the location where you installed the package. 您可以看到我将angular-cli.json的路径添加到了安装软件包的位置。
Try add that section and start up your project again. 尝试添加该部分,然后再次启动您的项目。
Note: Popper.js should be included before bootstrap. 注意:在引导程序之前应包含Popper.js。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.