Reputation: 31
I'm trying to use external JavaScript files in angular 7 project and for this I have added multiple JavaScript files to angular.json file as in image
JavaScript files added in angular.json file
and also loading default multiple JavaScript files on page with make any reference manual so, from where they are refereed.
Please suggest the right way to use external JavaScript files in Angular 7 and also suggest how should we use the packages JavaScript files in Angular 7.
Thanks in advance.
Upvotes: 0
Views: 4313
Reputation: 12980
To import jQuery into an Angular app, you need to install it properly. Opinionated answer below.
npm install jquery --save
import $ from 'jquery';
https://stackblitz.com/edit/angular-8kcpz2?file=src%2Fapp%2Fhello.component.ts
import { Component, Input } from '@angular/core';
import $ from 'jquery';
@Component({
selector: 'hello',
template: `<h1>Why are you still using jquery? </h1>`,
styles: [`h1 { font-family: Lato; }`]
})
export class HelloComponent implements OnInit {
@Input() name: string;
consturctor() {}
ngOnInit() {
alert($('h1').text())
}
}
You do not need to add it to your angular.json
file.
Upvotes: 1