2

I have tried running the following npm install but it doesnt fix anything. npm install jquery --save npm install @types/jquery --save-dev

I have added "scripts": ["../node_modules/jquery/dist/jquery.min.js"], in .angular-cli.json file.

app.component.ts

import { Component } from '@angular/core';
declare var $:any;


@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})

export class AppComponent {

title = 'jQuery works!';


       onToggle(){

$('.test').slideToggle();

       }

}

Error: $ is not defined

Sunil Bind
  • 507
  • 1
  • 5
  • 18

1 Answers1

1

Did you try import jquery like this?

import * as $ from 'jquery';
Nour
  • 5,609
  • 3
  • 21
  • 24