Home Angular 12 How to add jquery in angular 12?

How to add jquery in angular 12?

by therichpost
2 comments
How to add jquery in angular 12?

Hello to all, welcome to therichpost.com. In this post, I will tell you, How to add jquery in angular 12?

Angular 12 came and if you are new in angular then please check below link for better understanding:

  1. Angular 12 Tutorials
Add and Run Jquery in Angular
Add and Run Jquery in Angular

Here is the code snippet for How to add jquery in angular 12? and below follow carefully:

1. Here are the basics commands to install angular 12 on your system:

npm install -g @angular/cli 

ng new angularjquery //Create new Angular Project

cd angularjquery // Go inside the Angular Project Folder

ng serve --open // Run and Open the Angular Project

http://localhost:4200/ // Working Angular Project Url

2. After done with above, you need to run below commands to set jquery environment into your angular 10 application:

npm install --save jquery

3. Now you need to add below code into your angular.json file:

"scripts": [...
              "node_modules/jquery/dist/jquery.min.js"
           ]
...

4. Now you need to add below code into src/app/app.component.ts file:

...
declare let $: any;
export class AppComponent {
  ...
  ngOnInit() {
  $('body').addClass('df');
  }
}

 

In the end, don’t forgot to run ng serve command. If you have any query then do comment below.

When script will execute then you will see your body tag has class name “df”.

Note: Friends, In this post, I just tell the basic setup and things, you can change the code according to your requirements.

I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad because with your views, I will make my next posts more good and helpful.

Jassa

Thank you.

You may also like

2 comments

Vinicius July 14, 2021 - 10:17 pm

Thanks!

Reply
Ajay Malhotra July 15, 2021 - 3:57 am

Welcome 🙂

Reply

Leave a Comment

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