// 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();
import * as $ from 'jquery'
//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");
});
});
}
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);
../node_modules/jquery/dist/jquery.min.js