简体   繁体   English

在jQuery中使用组件选择器

[英]Use component selector in jquery

I am working on my Angular 4 project. 我正在从事Angular 4项目。 I have two components, one is TaskCardComponent and CalendarComponent. 我有两个组件,一个是TaskCardComponent和CalendarComponent。 There is a css class in CalendarComponent called 'calendar'. CalendarComponent中有一个css类,称为“ calendar”。 What I want to do is append TaskCardComponent-html to this 'calendar' class div using jquery in CalendarComponent .ts file. 我想做的是使用CalendarComponent .ts文件中的jquery将TaskCardComponent-html附加到此“ calendar”类div中。 I know there is a way to use selector of component. 我知道有一种使用组件选择器的方法。 But I have requirement to use jquery only. 但我有要求只使用jquery。 How can I do that? 我怎样才能做到这一点? Thanks in advance. 提前致谢。

Go to that component where you want to use jQuery. 转到您要使用jQuery的组件。 declare this variable above the class 在类上方声明此变量

declare var jQuery:any

This jQuery variable is availabe in your component and you can use as you use jQuery in javascript. 该jQuery变量在您的组件中可用,您可以在javascript中使用jQuery时使用。

jQuery("...")

One more thing to check before using. 使用前还要检查一件事。 you must add jquery reference in Index.html 您必须在Index.html中添加jquery引用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM