Angular項目中引入jQuery

 

npm install --save jquery

npm install @types/jquery --save

 

在對應的組件中引入node

import * as $ from "jquery";

 在整個項目中一次聲明,不用重複引入的方式:jquery

.angular-cli.json文件中添加npm

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "map"
  },
  "apps": [
    {
     ...
      "styles": [
       ...
      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.js",
       ...
      ],
      ...
    }
  ],
}
相關文章
相關標籤/搜索