Hello to all, welcome to therichpost.com. In this post, I will tell you, Add and Run Jquery in Angular 7.
Angular is growing very fastly and popular as single page application. Today I am working with Angular 7 and wanted to run some jquery methods and I succeed and I am sharing that tricks what I did on my app.
I have written so many post related to jQuery because jQuery is my first love and today I also use jQuery in my many projects.
Here is the working image, I added dynamic class to body tag with jQuery:

Here is the working and tested code and you need to follow and into your Angular 7 application:
1. Very first, you need to run below command into your terminal :
$ npm install jquery --save
2. Now, you need to add below jquery file path into your Angular 7 application angular.json file:
....
"scripts": ["node_modules/jquery/dist/jquery.js"]
....
3. Now you need to add below code into your app.component.ts file:
import * as $ from 'jquery';
export class AppComponent {
ngOnInit() {
$('body').addClass('df');
}
}
4. In this end run your Angular 7 application and you will see, new class will be added to body tag.
if you have any query related to this post, then please do comment below or ask question.
Thank you,
Alisha,
TheRichPost.

Leave a Reply
You must be logged in to post a comment.