Sometimes when I build an Angular custom directive, I will hear a comment as to, if it is an Angular directive, it should not use jQuery code in it, because it should be built in an AngularJS way.
And I thought it might be true, but is it possible? For example, what if the directive template has 2 sections, one is the words and one is the tiny images (such as review stars), and so you need 2 sections in your template, labeled as .description
and .star-images
-- so then you should need to use $.find(".description")
to find that section inside your template if you need to do something to it or inside it. jqLite won't work as jqLite's find()
is limited to tags only.
Another example is, what if you have a directive that doesn't have a template, but just limit the keypress to digits only, say, for an input box. So you don't want your directive to have a template as <input type="text">
but just want the user of the directive to say <input type="text" digits-input-only>
and your directive is called digitsInputOnly
. So in that case, don't you need to use jQuery's elem.on()
or elem.bind()
to listen on keypress or keydown events, and when the key down code is not a digit, then do a event.preventDefault()
? So in that case, it has to use jQuery?
Or other there other ways to do it so that you really shouldn't need to use jQuery?