Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在angular中管理js文件_Javascript_Jquery_Angular - Fatal编程技术网

Javascript 如何在angular中管理js文件

Javascript 如何在angular中管理js文件,javascript,jquery,angular,Javascript,Jquery,Angular,我正在开发一个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", "favico

我正在开发一个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/”下,以“not found”错误结束

angular.cli.json文件,在“angular/src”根路径中查找“node_modules/jquery/dist/jquery.min.js”

有没有办法在不改变我的文件夹结构的情况下解决这个问题


需要有人的宝贵帮助。

是的。从angular.cli.json中删除脚本链接,然后将其包含在带有脚本标记的索引html中


它工作正常。

最简单的方法是直接在index.html中链接js文件

如果您想让angular编译和维护它,请检查此链接


我也遵循了同样的原则。我已经使用npm安装了jquery。我已将其包含在angular.cli.json文件中的脚本中。此外,我还在component.ts文件中添加了“import*as$from'jquery';”。但我仍然收到“$未定义”错误。您可能没有添加打字。默认情况下,JQuery将不会有打字。因此,角度编译器将不知道如何处理这些文件。请参阅此链接