【问题标题】:jQuery not working in angular 4jQuery 不能在 Angular 4 中工作
【发布时间】:2018-01-11 01:19:07
【问题描述】:

我尝试运行以下 npm install 但它没有解决任何问题。 npm install jquery --save npm install @types/jquery --save-dev

我在 .angular-cli.json 文件中添加了“脚本”:[“../node_modules/jquery/dist/jquery.min.js”]。

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();

       }

}

错误:$ 未定义

【问题讨论】:

标签: angular


【解决方案1】:

你试过这样导入 jquery 吗?

import * as $ from 'jquery';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-22
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 2018-05-03
    • 2017-12-29
    • 2018-10-29
    • 1970-01-01
    相关资源
    最近更新 更多