jquery - “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');
});
}
}
解决方案
您必须声明$如下,
declare var $;
代替
import * as $ from 'jquery';
更新
更新您的angular.json
文件
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
//Here ripple module path
],
这将解决您的错误 -> $ 未声明以及涟漪。
推荐阅读
- r - unnest() 错误:“不能从数字转换为字符”
- php - 从 url 中删除 dir 和 .php
- r - 如何计算反应柱的加权百分比?
- go - 是什么导致“恐慌:运行时错误:无效的内存地址或 nil 指针取消引用”?
- amazon-web-services - Set-AWSSamlRoleProfile 失败并显示“无法设置凭证:“选择”应至少包含一个元素。” 错误
- javascript - 当我单击元素时,它不会阻止默认操作
- c - 如何在不打印菜单两次的情况下制作一个与父进程的菜单交互的叉子?
- c++ - 从 T 转换为 unsigned int,可能会丢失数据
- string - 使用pyspark,spark + databricks时如何将完全不相关的列添加到数据框中
- javascript - 使用 KaTex 渲染数学