如何在 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.