简体   繁体   English

JHipster - 无法在 angular.json 中添加 jquery 路径

[英]JHipster - cant add jquery path in angular.json

Normaly it is really easy to add SCSS styles and jQuery path to angular project, we just have to add it on script: [] section,通常,将SCSS styles 和jQuery路径添加到 angular 项目真的很容易,我们只需在脚本中添加它: [] 部分,

However:然而:

Checking the angular.js generated from jhipster , I can see the architect part is empty:检查从angular.js生成的jhipster ,我可以看到架构师部分是空的:

{
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": {
        "consuldent": {
            "root": "",
            "sourceRoot": "src/main/webapp",
            "projectType": "application",
            "architect": {}
        }
    },
</i>

Adding path to my index.html work for me but I want to know if there is another method.添加路径到我的index.html对我有用,但我想知道是否有另一种方法。

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

Here is the solution for "how to add jquery in jhipster " (version angular ):以下是“如何在jhipster中添加jquery ”的解决方案(版本angular ):

 npm install --save --save-exact jquery
 npm install --save-dev --save-exact @types/jquery 

and in your vendor.ts (location: src/main/webapp/app/vendor.ts ) and add:并在您的vendor.ts (位置: src/main/webapp/app/vendor.ts )并添加:

....
import 'jquery/dist/jquery.js';
import 'jquery/dist/jquery.min.js';
....

then add this in your component ( just next imports) where you want to use jquery :然后将其添加到您想要使用jquery的组件中(只是下一个导入):

....
import * as $ from 'jquery';
.... 

and in your ngOnInit function:并在您的ngOnInit function 中:

 ngOnInit(): void {
    $(()=>{
      $('#id').codejs....;
    });
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM