Is That A Good Practice To Use Jquery With Angularjs?
Solution 1:
No, it is not a good idea. You are using jQuery coding practices in an Angular app and this will cause you headaches - for once because those practices go against the Angular spirit, and also because you won't reap the benefits of Angular.
One of the most important parts in Angular development is: you shouldn't manipulate the DOM from your controllers, ever. This is fine in jQuery, but in Angular, you should modify your model and let Angular render it. Angular has a templating mechanism built in which you should use to load HTML fragments. If you need to create HTML dynamically, you should do so in a directive. Everything else violates the "separation of concerns" principle.
If you use jQuery or native DOM methods to manipulate input settings or modify the DOM, you set up yourself for a fight with Angular over it which will result in a lot of hard-to debug errors. One of the main points of Angular is two-way databinding which is not a useful feature if you insist on binding data to HTML on your own. Maybe one of the simpler templating libraries like moustache or knockout would be more to your liking?
To reap the benefits of Angular means letting go some tried and true practices and learning about the built-in directives, especially ng-repeat
, ng-if
, ng-class
, ng-click
and ng-change
and maybe something like Angular UI.
Solution 2:
Big NO. It's not a good idea to use jQuery with angular.js. jQuery does different thing and angular.js does different things. jQuery manipulates the DOM and add, append, remove element dynamically. In other hands, angular.js just manipulate model data but you can use jqlite built in with angular.js.
Post a Comment for "Is That A Good Practice To Use Jquery With Angularjs?"