Hello to all, welcome to therichpost.com. In this post, I will tell you, How to add and run jquery in angular 10?
Angular 10 came and if you are new in angular then please check below two links for better understanding:
Here is the code snippet and below follow carefully:
1. Here are the basics commands to install angular 10 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”.
Jassa
Thank you.
Recent Comments