2

I am working on an angular project with my friends for our class project and we want a custom Js file with certain methods to be added to our project but adding this to the app.component.html file inside didn't work. How to add the files to the project?

1

2 Answers 2

4

you can do this in two ways:

If you want the custom js to be global, add the path to scripts array in angular-cli.json file

"scripts": [
    "../custom" 
 ];

Otherwise if you want the custom js to be in specific component,

import * as custom from './custom';
custom.method();
Sign up to request clarification or add additional context in comments.

Comments

0

firsfile and secondfile are the member variable of typescript class

Initalise this member var in constructor like this.
this.firstFile= require('./firstfile'); // firstfile.js
this.secondFile= require('./secondfile'); //secondfile.js

now use same as you do in JavaScript after importing module files.

Hope it will help

1 Comment

I don't think so is their is any wrong in that . I am also use some protobuffer JavaScript file in my angular project , it run fine. so if you give any negative rating then please explain it why you are giving the negative rating.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.