首页 > 解决方案 > “JQuery”类型不存在属性“涟漪”'。在角度分量中

问题描述

我正在尝试在 angular 上实现 jquery 函数,但终端返回以下错误:

类型“JQuery<HTMLElement>”上不存在属性“涟漪”

在我的控制台上,我收到以下错误:错误 ReferenceError: $ is not defined

这是我的代码片段

import { Component, OnInit } from '@angular/core';
import * as $ from 'jquery';
import 'jqueryui';

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

export class HomeComponent implements OnInit {
  constructor() { }

  ngOnInit() {
    $(document).ready(function() {
      $('.image').ripples('show');
    });
  }
}

标签: jqueryangular

解决方案


您必须声明$如下,

declare var $; 

代替

import * as $ from 'jquery';

更新
更新您的angular.json文件

"scripts": [
              "node_modules/jquery/dist/jquery.min.js",
              //Here ripple module path
            ],

这将解决您的错误 -> $ 未声明以及涟漪


推荐阅读