Categories

Friday, November 22, 2024
#919814419350 therichposts@gmail.com
Angular7Javascript

How to include custom js file to all components in Angular 7?

Include custom js file to all components in Angular 7

Hello to all, welcome to therichpost.com. In this post, I will tell you, How to include custom js file to all components in Angular 7?

Angular 7 getting more popularity day by day and I also enjoy to work in it,

I will custom js file to all the Angular 7 components programmatically.

Here are the steps you need to follow:

 

1. You need to create new src/custom.js file and add below code:

alert("test");

How to include custom js file to all components in Angular 7

 

 

2. Now add below code into your angular.json file:

...
"scripts": ["src/custom.js"]
...

 

3. After execute your Angular 7 application, you will get alert on every component load and below you can see added file code:

added_custom_js_file

 

If you have any query related to this post, then please do comment below or ask question.

Thank you,

Alisha,

TheRichPost

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

5 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.