Categories

Saturday, April 27, 2024
#919814419350 therichposts@gmail.com
Angular6Jquery

How to run jQuery in Angular 6?

Run jQuery in Angular 6 - The Rich Post

Hello to all, welcome to therichpost.com. In this post, I will tell you, How to run jQuery in Angular 6?

Angular is growing very fastly and popular as single page application. Today I am working with Angular 6 and wanted to run some jquery methods and I succeed and I am sharing that tricks what I did on my app.

Here are the following steps to run or include jQuery into your Angular 6 app:

1. First you need to run below command into your terminal:
  $ npm install jquery --save
2. Add below jquery file path into your angular.json file:
"scripts": ["node_modules/jquery/dist/jquery.js"]
3. Import jquery file into your app.module.ts file:
import * as $ from 'jquery';
4. Declare and finally add jquery code into your app.component.ts file:
declare var $: any;

export class AppComponent {

  ngOnInit() {

  $('body').addClass('df');

  }

}

And you are done.

jquery-angular6

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

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 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

3 Comments

Leave a Reply

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