Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.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
如何调用Angular component中assets文件夹下单独文件中的外部Javascript函数?_Javascript_Angular_Angular Ui Router_Tsconfig - Fatal编程技术网

如何调用Angular component中assets文件夹下单独文件中的外部Javascript函数?

如何调用Angular component中assets文件夹下单独文件中的外部Javascript函数?,javascript,angular,angular-ui-router,tsconfig,Javascript,Angular,Angular Ui Router,Tsconfig,} 我试过以上两种方法 在第一种方式中,我无法编译代码,因为它会抛出类似“错误TS5055:无法写入文件'main.js',因为它会覆盖输入文件”的错误。在本例中,我还添加了“allowJs:true” 在方法2中,我得到了类似“无法读取未定义的属性'call'”的错误 帮我解决这个问题。提前感谢。据我所知,您正在使用angular cli。您已经在cliconfig中加载了脚本。 以下是您如何完成的wiki:据我所知,您正在使用angular cli。您已经在cliconfig中加载了脚本。

}

我试过以上两种方法

在第一种方式中,我无法编译代码,因为它会抛出类似“错误TS5055:无法写入文件'main.js',因为它会覆盖输入文件”的错误。在本例中,我还添加了“allowJs:true”

在方法2中,我得到了类似“无法读取未定义的属性'call'”的错误


帮我解决这个问题。提前感谢。

据我所知,您正在使用angular cli。您已经在cliconfig中加载了脚本。
以下是您如何完成的wiki:

据我所知,您正在使用angular cli。您已经在cliconfig中加载了脚本。
以下是您可以完成的wiki:

正如我在图像中看到的文件夹结构一样,我相信您正在使用angular cli进行此操作,因此您可以通过在脚本数组中的.angular cli.json文件中包含脚本的路径来包含外部脚本

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "dummy-project"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "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": [
        "styles.css"
      ],
      "scripts": ['assets/filename.js],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "src/tsconfig.spec.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "e2e/tsconfig.e2e.json",
      "exclude": "**/node_modules/**"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "component": {}
  }
}

正如我在图像中看到的那样,我相信您正在为此使用angular cli,因此您可以通过在脚本数组中的.angular cli.json文件中包含该脚本的路径来包含外部脚本

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "dummy-project"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "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": [
        "styles.css"
      ],
      "scripts": ['assets/filename.js],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "src/tsconfig.spec.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "e2e/tsconfig.e2e.json",
      "exclude": "**/node_modules/**"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "component": {}
  }
}

如果您使用的是angular cli,请尝试将其添加到angular cli脚本阵列中。这会将脚本加载到浏览器中。如果使用angular cli,请尝试将其添加到angular cli脚本阵列中。这将把脚本加载到浏览器中。