Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.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 如何包含我自己的JS/jQuery函数';s文件在我的Angular 5项目中全局_Javascript_Jquery_Angular - Fatal编程技术网

Javascript 如何包含我自己的JS/jQuery函数';s文件在我的Angular 5项目中全局

Javascript 如何包含我自己的JS/jQuery函数';s文件在我的Angular 5项目中全局,javascript,jquery,angular,Javascript,Jquery,Angular,我有一个JS/jQuery函数的文件&我想在Angular 5项目的所有组件中使用它。那么,我如何在我的项目中使用它的功能呢 注意:我已经安装了jQuery,并且可以在我的typescript中使用它。但是我想在typescript中使用我自己的JS/jQuery文件(app.JS)中的函数。我该怎么做呢?您可以将它们包含在文件资产(或其他地方)中,并进一步将它们添加到.angular cli.json中,路径应该是正确的。您可以在资产中添加一个名为js的文件夹,并将这些文件放在那里。并修改文件

我有一个JS/jQuery函数的文件&我想在Angular 5项目的所有组件中使用它。那么,我如何在我的项目中使用它的功能呢


注意:我已经安装了jQuery,并且可以在我的typescript中使用它。但是我想在typescript中使用我自己的JS/jQuery文件(app.JS)中的函数。我该怎么做呢?

您可以将它们包含在文件资产(或其他地方)中,并进一步将它们添加到
.angular cli.json
中,路径应该是正确的。您可以在资产中添加一个名为js的文件夹,并将这些文件放在那里。并修改文件
.angular cli.json
如下

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "angular-test"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        ".htaccess",
        "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": [
        "../node_modules/font-awesome/css/font-awesome.min.css",
        "assets/css/styles.min.css",
        "styles.css"
      ],
      "scripts": [
        "assets/js/app.js"   /* add all such files HERE */
      ],
      "environmentSource": "environments/env.ts",
      "environments": {
        "dev": "environments/env.ts"
      }
    }
  ],

  ...
}

@Komal_Chandra,告诉我它在你的案子中是否有效不,它不起作用。如何在typescript中导入此JS文件(app.JS)?像导入jQuery插件一样,我使用了“jQuery”中的“import*as$”。通常jQuery在Angular项目中使用不多。然而,它需要一些效果和所有。这些简单的任务可以通过在资产中添加这些文件来完成,并在angular-cli.json中提到。根本不需要安装jquery包