在我的项目中,我下载了本地副本 of Bootstrap、Jquery和Popper。但是,当我将它们包含在Angular6项目中时,我会遇到错误。
文件在angular-test\src\assets\common的位置
我已经在Angular.json中projects属性下包含了它们的路径。
"projects": {
"angular-test":
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css",
"src/assets/common/css/vendor/bootstrap/bootstrap.css"
],
"scripts": [
"src/assets/common/javascripts/vendor/jquery/jquery-3.2.1.js",
"src/assets/common/javascripts/vendor/popper/umd/popper.js",
"src/assets/common/javascripts/vendor/bootstrap/bootstrap.js"
]
},并在index.html中使用如下所示:
<head>
...
<link rel="stylesheet" media="screen" href="bootstrap.css">
</head>
<body>
<app-root signup="success1"></app-root>
<script src="jquery-3.2.1.js" type="text/javascript"></script>
<script src="popper.js" type="text/javascript"></script>
<script src="bootstrap.js")" type="text/javascript"></script>
</body>我所犯的错误是
Refused to apply style from 'http://localhost:4200/bootstrap.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
jquery-3.2.1.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
localhost/:1 Refused to execute script from 'http://localhost:4200/jquery-3.2.1.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
popper.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
localhost/:1 Refused to execute script from 'http://localhost:4200/popper.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
bootstrap.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
localhost/:1 Refused to execute script from 'http://localhost:4200/bootstrap.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.发布于 2018-09-17 13:51:43
问题是,由于我已经在scripts属性中指定了Angular.json中的javascripts,所以不需要在index.html中显式添加它们。我评论了下面几句,它起了作用
<!--script src="jquery-3.2.1.js" type="text/javascript"></script>
<script src="popper.js" type="text/javascript"></script>
<script src="bootstrap.js" type="text/javascript"></script-->https://stackoverflow.com/questions/52345079
复制相似问题