Angular项目中引入jQuery

npm install --save jquery

npm install @types/jquery --save

在对应的组件中引入

import * as $ from "jquery";

 在整个项目中一次声明,不用重复引入的方式:

.angular-cli.json文件中添加

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "map"
  },
  "apps": [
    {
     ...
      "styles": [
       ...
      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.js",
       ...
      ],
      ...
    }
  ],
}

猜你喜欢

转载自www.cnblogs.com/viola-sh/p/9766233.html