use jquery in angular
// In the console // First install jQuery npm install --save jquery // and jQuery Definition npm install -D @types/jquery =======================================(in angular) import * as $ from 'jquery'; // $('#elemId').width(); // OR // CommonJS style - working with "require" import $ = require('jquery') // $('#elemId').width();
Source: stackoverflow.com
import jquery into angular 8
import * as $ from 'jquery'
jquery in Angular
//first step: npm install --save jquery npm install -D @types/jquery //secong step: "scripts": [ "node_modules/jquery/dist/jquery.min.js" ] //third step: <script type="text/javascript" src="assets/js/jquery-2.1.1.min.js"></script> //fourth step in .ts file: import * as $ from 'jquery'; ngOnInit(): void { this.GET_LOGIN_FORM_VALUE(); $(document).ready(() => { $("button").click(() => { $("h3").css("color", "red"); }); }); }
declare * angular jquery
declare var $:any;
add jquery angular
../node_modules/jquery/dist/jquery.min.js
Source: blog.bitsrc.io
how to use jquery in angular
import {bootstrap} from '@angular/platform-browser-dynamic'; import {Component, ViewChild, ElementRef, AfterViewInit} from '@angular/core'; declare var $:JQueryStatic; @Component({ selector: 'ng-chosen', template: `<select #selectElem> <option *ngFor="#item of items" [value]="item" [selected]="item === selectedValue">{{item}} option</option> </select> <h4> {{selectedValue}}</h4>` }) export class NgChosenComponent implements AfterViewInit { @ViewChild('selectElem') el:ElementRef; items = ['First', 'Second', 'Third']; selectedValue = 'Second'; ngAfterViewInit() { $(this.el.nativeElement) .chosen() .on('change', (e, args) => { this.selectedValue = args.selected; }); } } bootstrap(NgChosenComponent);
Source: stackoverflow.com