如何在Angular 6中包含外部html文件和js文件?

问题描述:

我想在Angular 6项目中包含一些html文件并在某些外部js文件中使用函数. 如何在Angular 6中包含外部html文件和js文件?

I want to include some html files and use functions in some external js files in my Angular 6 project. How can I include external html file and js file in Angular 6?

您可以将这些文件放在src/assets文件夹下,并在angular.json中指定路径.意思是,您可以将文件包含在src/assets/htmlsrc/assets/js文件夹下.

You can place those files under src/assets folder and specify the path in angular.json. Meaning, you can keep the files to be included under src/assets/html and src/assets/js folders.

angular.json配置,例如:

"build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/browser",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "progress": false,
            "showCircularDependencies": true,
            "polyfills": "src/polyfills.ts",
            "assets": [
              "src/assets",
              "src/favicon.ico",
              "src/robots.txt",
              "src/sitemap.xml"
            ],
            "styles": [
              "src/styles.css",
              "src/assets/css/home-style-min.css",
              "src/assets/css/prism-min.css"
            ],

放置在此处的所有文件都将在构建时选择.

All the files placed there will be picked at build time.