[英]Include JQuery-Ui in Angular 7 project for external .js file
我有一個 Angular 7 項目,我正在嘗試包含 JQuery-Ui 插件。 我已經安裝了 JQuery 和插件並將其添加到 angular.json 中的腳本數組中。 我在 jquery.js 文件中有我所有的 JQuery 函數,我已添加到資產文件夾並將所述文件導入到我的 component.ts 文件中。 JQuery 正在運行,但我無法使用插件功能。 我也嘗試將 'jquery-ui' 導入 jquery.js 文件,但沒有任何積極的結果。 非常感謝任何幫助。
angular.json
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/jquery-ui/jquery-ui.js"
]
jquery.js
import * as $ from 'jquery';
$(document).ready(function(){
$('#page_top').children().hover(
function(){
$(this).animate({color: 'red'}, 200)
},
function(){
$(this).animate({color: 'blue'}, 200)
}
);
})
你有什么錯誤? 您的 index.html 是否包含 jQuery? 據我所知,如果您將其包含在scripts
它會自動為您執行此操作。 如果你走那條路,你可以做
//component.ts
declare var $; //you can now use $ just like normal jQuery
@Component({})
我通常不將 jQuery 與 Angular 一起使用,但過去必須為一個項目執行此操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.