I've been learning Angular and now I'm trying to understand a large piece of code that was given me, and it has a lot of $()
in the code containing a variable inside and a method call $(variable_name).method()
or even a CSS class inside, between double quotes $(".class_name").method()
.
I understand $scope
well, but I get confused with the syntax I explained above. Can someone explain what is it? Thanks in advance. /Teo
P.S.: The code is a directive, so I assume JS don't have this syntax except for the Angular framework.
答案 0 :(得分:3)
Angular uses a subset of jQuery called jqLite. Here you can read a documentation: https://docs.angularjs.org/api/ng/function/angular.element Using $() function is basically wrapping an element so you can call jqLite function on it an chaining them. In your particular example $(variable_name).method()
will wrap a DOM node stored in variable variable_name
with jqLite and then run method
on it. $(".class_name").method()
is another usage of $()
. It works the same as querySelectorAll()
but instead of collection of DOM nodes will return collection of jqLite wraped nodes and then do the same - run method
on each of them.