Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include external html files and js file in Angular 6?

Tags:

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?

like image 824
affeto Avatar asked Jul 11 '18 06:07

affeto


People also ask

How do I include an external HTML file in angular 6?

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.

How can you integrate AngularJS with HTML?

AngularJS Introduction. AngularJS is a JavaScript framework. It can be added to an HTML page with a <script> tag.

What is the most appropriate file to configure external .js files in angular?

Add external JS files If you want include any js library in your angular application like as jquery, bootstrap etc.. You can use npm command for install this library. After installing this library add them in styles and scripts array in angular. json respectively css and js.


1 Answers

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.

like image 168
eduPeeth Avatar answered Sep 28 '22 19:09

eduPeeth