In jQuery, we often have an event trigger, then from the element that raised the event, we traverse the DOM to find another element, which is then processed. For example, your example:
// some event causes this code to execute: $(this).parent().addClass('.loading');
In AngularJS, we declare where the manipulation points are at the beginning of the HTML (for example, ng-class, as @blesh suggests), then the events change the $ scope properties, and Angular automatically performs the DOM manipulation for us. For instance:.
<div ng-controller="MyCtrl" ng-class="loadingClass">parent <a ng-click="loadingClass='loading'">child</a> </div>
Controller:
function MyCtrl($scope) {
Above, by clicking on the "child" link, the value of $ scope.loadingClass is changed. Angular will notice the change and apply the new class to the parent div.
For more complex manipulations, a special directive like @ jm-shows is required.
jQuery: events result in DOM traversal and DOM manipulation code (required).
Angular: events change $ scope and magic happens (in our declarative HTML).
source share