我正在开发一个 MEAN 应用程序,我的文件夹结构如下:
我在/angular/src/assets/js 下添加了一个 js 文件来存储一些 jQuery 的东西。
为此,我使用 npm 安装了 jQuery。
现在我需要通过 angular.cli.json 文件调用该 js 文件。
angular.cli.json:
"apps": [
{
"root": "angular/src",
"outDir": "angular/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"
],
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../src/assets/js/custom.js"
],
由于我将根指向“angular/src”,因此存在将 jquery.min.js 包含在位于“mean/node_modules/”下的脚本部分并以“未找到”错误结束的问题.
angular.cli.json 文件在“angular/src”根路径中查找“node_modules/jquery/dist/jquery.min.js”。
有什么方法可以在不改变我的文件夹结构的情况下解决这个问题吗?
需要某人的宝贵帮助。
最佳答案
最简单的方法是直接在index.html中链接js文件。
如果你希望它由 Angular 编译和维护,请检查此链接
How to include external js file in Angular 4 and call function from angular to js
关于javascript - 如何在Angular中管理js文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49857172/