jQuery的触发相当于angularjs [英] jquery trigger equivalent in 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有jqLite内置到它。请参考文档以查看可用的方法,
AngularJS has jqLite built into it. Refer the docs to see the available methods,
为您的方案:
$不会angularJS工作,angular.element是$等效。
但jqLite是非常有限不支持的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('#富')?但请记住,我们正在使用jqLite,所以我们必须使用angular.element,以便能够使用元素的jqLite方法。
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
jqLite不支持点击()。解决方法是使用。就绪()
jqLite does not support click(). The workaround would be to use .ready()
element.ready(function() {
console.log('Click');
});
这篇关于jQuery的触发相当于angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!