Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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
手动包含jquery文件时,无法在Angular 9中找到jquery文件_Jquery_Angular_Angular9 - Fatal编程技术网

手动包含jquery文件时,无法在Angular 9中找到jquery文件

手动包含jquery文件时,无法在Angular 9中找到jquery文件,jquery,angular,angular9,Jquery,Angular,Angular9,我尝试将jquery库文件添加到assets文件夹中,并将目录添加到angular.json中的脚本中,但当我运行ng serve angular时,告诉我jquery库不存在,我正在使用angular版本9。 我不知道问题出在哪里请帮忙 这将显示错误消息: An unhandled exception occurred: Script file assets/js/jquery-3.5.1.slim.min.js does not exist. angular.json文件: { "

我尝试将jquery库文件添加到assets文件夹中,并将目录添加到angular.json中的脚本中,但当我运行ng serve angular时,告诉我jquery库不存在,我正在使用angular版本9。 我不知道问题出在哪里请帮忙

这将显示错误消息:

An unhandled exception occurred: Script file assets/js/jquery-3.5.1.slim.min.js does not exist.
angular.json文件:

{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"HorsesClubFrontend": {
  "projectType": "application",
  "schematics": {},
  "root": "",
  "sourceRoot": "src",
  "prefix": "app",
  "architect": {
    "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
        "outputPath": "dist/HorsesClubFrontend",
        "index": "src/index.html",
        "main": "src/main.ts",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "tsconfig.app.json",
        "aot": true,
        "assets": [
          "src/favicon.ico",
          "src/assets"
        ],
        "styles": [
          "src/styles.css",
          "assets/css/bootstrap.min.css"
        ],
        "scripts": [
          "assets/js/jquery-3.5.1.slim.min.js",
          "assets/js/bootstrap.min.js",
          "assets/js/popper.min.js"]
      },
      "configurations": {
        "production": {
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.prod.ts"
            }
          ],
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "extractCss": true,
          "namedChunks": false,
          "extractLicenses": true,
          "vendorChunk": false,
          "buildOptimizer": true,
          "budgets": [
            {
              "type": "initial",
              "maximumWarning": "2mb",
              "maximumError": "5mb"
            },
            {
              "type": "anyComponentStyle",
              "maximumWarning": "6kb",
              "maximumError": "10kb"
            }
          ]
        }
      }
    },
    "serve": {
      "builder": "@angular-devkit/build-angular:dev-server",
      "options": {
        "browserTarget": "HorsesClubFrontend:build"
      },
      "configurations": {
        "production": {
          "browserTarget": "HorsesClubFrontend:build:production"
        }
      }
    },
    "extract-i18n": {
      "builder": "@angular-devkit/build-angular:extract-i18n",
      "options": {
        "browserTarget": "HorsesClubFrontend:build"
      }
    },
    "test": {
      "builder": "@angular-devkit/build-angular:karma",
      "options": {
        "main": "src/test.ts",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "tsconfig.spec.json",
        "karmaConfig": "karma.conf.js",
        "assets": [
          "src/favicon.ico",
          "src/assets"
        ],
        "styles": [
          "src/styles.css"
        ],
        "scripts": []
      }
    },
    "lint": {
      "builder": "@angular-devkit/build-angular:tslint",
      "options": {
        "tsConfig": [
          "tsconfig.app.json",
          "tsconfig.spec.json",
          "e2e/tsconfig.json"
        ],
        "exclude": [
          "**/node_modules/**"
        ]
      }
    },
    "e2e": {
      "builder": "@angular-devkit/build-angular:protractor",
      "options": {
        "protractorConfig": "e2e/protractor.conf.js",
        "devServerTarget": "HorsesClubFrontend:serve"
      },
      "configurations": {
        "production": {
          "devServerTarget": "HorsesClubFrontend:serve:production"
        }
      }
    }
  }
}},
     "defaultProject": "HorsesClubFrontend"
}
资产文件夹:


要在angular中添加jquery,必须遵循以下步骤

第一步 将index.html文件中的jquery文件添加到head标记中

步骤2 还需要安装两个npm软件包

npm ijquery@3.5.1 npm i@types/jquery 步骤3 将jquery添加到angular.json文件到脚本数组中

脚本:[ node_modules/jquery/dist/jquery.js ]
请尝试以上步骤,我希望这将对您有所帮助。

感谢您的回答,感谢您的工作方式,但我找到了另一种方法,即直接安装引导npm安装引导-将库保存并包含到angular.json:

        "styles": [
          "./node_modules/bootstrap/dist/css/bootstrap.css",
          "src/styles.css"
        ],
        "scripts": [
          "./node_modules/jquery/dist/jquery.js",
          "./node_modules/bootstrap/dist/js/bootstrap.js"
        ]

而且它工作得很好

很高兴听到:-