Is it a bad practice to use jQuery in Angular?

11,846

Solution 1

Yes it's a bad practice, but sometimes it will save you much time, especially when you are looking for a plugin, Do it when necessary only, and keep a note to switch it back when other solutions are available.

Solution 2

The first thing you should do is to read this thread on SO "Thinking in AngularJS" if I have a jQuery background?. This will give you some perspective.

When it comes to Angular, it the model that drives the view and most of the times direct DOM manipulation is not required.

For example if you are using DOM manipulation to show\hide element, add remove class or set style, then better to use ng-show\ng-class\ng-style directive.

But there are cases when DOM manipulation is required and that is the time you write directives and either use jqLite or jQuery to manipulate DOM.

My suggestion would be to avoid jQuery unless you have to incorporate a jquery plugin that is dependent on jQuery.

While developing always look if the inbuilt directives that can serve your purpose. If not can jqLite be used to achieve what is desired. Your final resort should be jQuery.

Solution 3

Well it's just two large resources, which makes your app "heavy". Otherwise it's only a preference thing. Personally I don't use jQuery with any of the reactive frameworks (Vue, React nor Angular).
Remember that anything jQuery can do, you can do with vanilla JS.

Share:
11,846
Davit Karapetyan
Author by

Davit Karapetyan

Updated on June 14, 2022

Comments

  • Davit Karapetyan
    Davit Karapetyan almost 2 years

    My question is the following. Should I avoid using any kind of jQuery code in Angular application as it seems legit to have only one thing interacting with DOM. Another question is if anyone came across problems where he couldn't find any other solution but writing a quick hack with jQuery.

    Thank YOU!

  • Davit Karapetyan
    Davit Karapetyan over 5 years
    Thank you, this made it a little bit clearer.
  • MD. Jubair Mizan
    MD. Jubair Mizan over 5 years
    Welcome Dear . If this clear to you then you can mark it as answerd !