如何在 Angular 6 中包含外部 html 文件和 js 文件? [英] How to include external html files and js file in Angular 6?

查看:49
本文介绍了如何在 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.

这篇关于如何在 Angular 6 中包含外部 html 文件和 js 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆