2

I have heard it is bad practice to use jquery in angular. I know if you need to do some DOM manipulation you should use directives. But why it is not recommended to use jquery directly in controller??

Siddharth
  • 6,966
  • 2
  • 19
  • 34
  • 1
    It's not jQuery usage in controllers that's frowned upon, it's dom-manipulation in controllers in general. – Yoshi Jul 22 '15 at 07:47
  • 2
    [“Thinking in AngularJS” if I have a jQuery background?](http://stackoverflow.com/questions/14994391/thinking-in-angularjs-if-i-have-a-jquery-background) Go through the post you will get your answer(s) – Satpal Jul 22 '15 at 07:48
  • Use jQuery if you want, it definitely adds convenience to DOM manipulations. Nothing wrong with having jQuery in Angular project. It's just you should limit its usage to directives. On the other hand, modern browsers in which single page app runs on often, they already have basically everything you might need what jQuery offers. – dfsq Jul 22 '15 at 07:52

2 Answers2

1

If you’re going to start an Angular JS application, Have a detailed read on Angular JS ng-directives and how to write custom directives.

The point is there will be always far better and easy way for dom-manipulations with less code in angular way, that will be easier for you to maintain and scale in future.

Also note that Angular itself provide JQlite for basic Jquery needs.

ssilas777
  • 9,672
  • 4
  • 45
  • 68
0

For having your code clear, logic, editable. It is a lot easier to write tests for one kind behaviour than many. In addition Angular has a lot of optimisation wich you wouldnt include yourself.

Next thing is you move out of controllers and it may result in collision with each other.

jQuery is for DOM manipulation as you wrote. Angular is more like application control. So If you make application you not need to hack it yourself :)

Paweł Smołka
  • 638
  • 5
  • 13