无法将.js文件加载到Angular 4应用程序中

问题描述 投票:0回答:1

我试图在我的Angular 4应用程序(模板 - https://startbootstrap.com/template-overviews/agency/)中使用预先设计的引导程序模板。 css样式已成功加载。但是在加载所需的.js文件时,它会发出以下警告。此外,.js文件应提供的效果不起作用。我该如何正确加载这些样式和.js文件?

在angular-cli.json中

"scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
    "assets/vendor/bootstrap/js/bootstrap.bundle.min.js",
    "assets/vendor/jquery-easing/jquery.easing.min.js",
    "assets/js/jqBootstrapValidation.js",
    "assets/js/contact_me.js",
    "assets/js/agency.min.js",
    "assets/js/agency.js"
  ],

在styles.css中

@import "~bootstrap/dist/css/bootstrap.min.css";
@import "~font-awesome/css/font-awesome.css";

在index.html中

<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Kaushan+Script' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700' rel='stylesheet' type='text/css'>
<!-- Custom Style  -->
<link rel="stylesheet" href="styles.css">

运行ng build时得到的警告

WARNING in ./~/raw-loader!./~/source-map-loader!./src/assets/vendor/bootstrap/js/bootstrap.bundle.min.js
Cannot find SourceMap 'bootstrap.bundle.min.js.map': Error: Can't resolve './bootstrap.bundle.min.js.map' in 'E:\MEAN 2\MEGATRON\src\assets\vendor\bootstrap\js'
@ ./~/script-loader!./src/assets/vendor/bootstrap/js/bootstrap.bundle.min.js 1:77-292
@ multi script-loader!./~/jquery/dist/jquery.min.js script-loader!./src/assets/vendor/bootstrap/js/bootstrap.bundle.min.js script-loader!./src/assets/vendor/jquery-easing/jquery.
easing.min.js script-loader!./src/assets/js/jqBootstrapValidation.js script-loader!./src/assets/js/contact_me.js script-loader!./src/assets/js/agency.min.js script-loader!./src/as
sets/js/agency.js
javascript css angular
1个回答
3
投票

确保bootstrap.bundle.min.js存在于vendor /目录中。我想你应该从node_modules /目录导入它。

"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/bootstrap/js/bootstrap.bundle.min.js",
"../node_modules/jquery-easing/jquery.easing.min.js",
...
]
© www.soinside.com 2019 - 2024. All rights reserved.