分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

Angular-如何在Angular2中使用jQuery及其插件

发布时间:2023-09-06 02:34责任编辑:胡小海关键词:jQueryAngular

搭建好环境后

一:首先在index.html中引用jquery,就像我们以前做的那样

    

二:然后我们编写我们的app.component.ts

import { Component,OnInit} from ‘@angular/core‘;declare var $:any;@Component({ ?selector: ‘app-root‘, ?templateUrl: ‘./app.component.html‘, ?styleUrls: [‘./app.component.css‘]})export class AppComponent ?implements OnInit{ ?ngOnInit() ?{ ???$("#title").html("<p>this is a string from jQuery html setting</p>"); ?}}

  首先需要使用declare生命我们的jQuery,使之成为一个可用的变量,然后,我们需要导入OnInit模块并实现,我们编写的jquery代码就在这里,文中展示了我们向id为title的标签替换内容,HTML页面是这样的

<div id="title" class="title"></div>

  这就意味着我们可以在Angular2中正常使用jQuery了

jquery插件引用:

  接下来做个简单的jQuery插件使用的例子,首先找一个我们要使用的jQuery插件,我用的是这个,3D视觉图片

  一:首先在index.html 中引用

  

  二:然后在我们刚才的app.component.ts中的ngOnInit中写入以下初始化插件代码

ngOnInit() ?{ ???$(".card").faceCursor({}); ????$("#title").html("<p>this is a string from jQuery html setting</p>"); ?}

    然后我们编写html,css,运行就可以了

Angular-如何在Angular2中使用jQuery及其插件

原文地址:https://www.cnblogs.com/zzy-run-92/p/10441804.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved