jQuery的触发相当于angularjs [英] jquery trigger equivalent in angularjs

查看:127
本文介绍了jQuery的触发相当于angularjs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用我的项目angularjs,我不希望包括jQuery的。
我想执行的jQuery相当于这AngularJS

I am using angularjs in my project and I dont want to include jQuery. I want to perform jquery equivalent of this in AngularJS

$('.someclass').trigger('create');

我在搜索互联网,但无法找到之一。
先谢谢了。

I searched in internet but couldnt find one. Thanks in advance.

推荐答案

AngularJS有jqLit​​e内置到它。请参考文档以查看可用的方法,

AngularJS has jqLite built into it. Refer the docs to see the available methods,

角jqLit​​e

为您的方案:

$不会angularJS工作,angular.element是$等效。
但jqLit​​e是非常有限不支持的ID选择器,意思是,你不能简单地使用angular.element通过class和id选择一个元素一样,

$ will not work in angularJS, angular.element is the equivalent of $. but jqLite being very limited does not support "selectors by id" meaning you cannot simply use angular.element to select an element by class or id like,

var element = angular.element('#foo')

您必须使用以下

var element = angular.element(document.querySelector('#foo'))

您可能会问,为什么不使用的document.getElementById('#富')?但请记住,我们正在使用jqLit​​e,所以我们必须使用angular.element,以便能够使用元素的jqLit​​e方法。

You may ask, "why not use document.getElementById('#foo')?" but remember we are using jqLite so we have to use angular.element in order to be able to use the jqLite methods on the element.

您可以使用.triggerHandler()而不是.trigger()。 jQuery的triggerHandler文档

you can use the .triggerHandler() instead of .trigger(). jQuery triggerHandler docs

jqLit​​e不支持点击()。解决方法是使用。就绪()

jqLite does not support click(). The workaround would be to use .ready()

element.ready(function() {
    console.log('Click');
});

这篇关于jQuery的触发相当于angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆