5

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?

1
  • I have read some solutions for similar questions for Angular 4, but I want want find a solution exactly for Angular 6. Commented Jul 11, 2018 at 6:38

1 Answer 1

4

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 configuration like :

"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.

Sign up to request clarification or add additional context in comments.

1 Comment

this doesnt work, you can fully remove the "assets" and nothing changes, any idea why?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.