CodeSOD: A Little Obtuse

AngularJS, (not to be confused with Angular, its successor project and ostensible replacement) made some… interesting design choices. Controllers existed in a tree, mapped to the DOM, and were glued together by a special object called $scope. You would store your data in the $scope, and depending on exactly how you did it, that data could be accessible at various levels within the tree. $scope also doubled as an event bus, so controllers could send messages up and down the tree as needed.

In short, there's a reason why AngularJS fell out of favor.

Still, during the era when AngularJS was the new trend, David's co-workers wanted to switch to using AngularJS. Unfortunately, they didn't know AngularJS, and only knew jQuery, so this snippet demonstrates their approach to building AngularJS applications:

<div ng-controller="myController" id="unique_abc">{{data}}</div>
function myController($scope){ $ = "static data"; $("#unique_abc").jQueryPlugin(); }

The HTML block attaches an Angular controller to the DIV. The JavaScript puts some meaningless data in the $scope, and then injects jQuery into the DOM the "Angular Way".

Then they did everything else in the application using the same jQuery code they had already been using, building DOM elements inside the <div> that way. In the end, they just added a gigantic dependency to their application and got absolutely no benefit out of it.

Oh wait, no, they did get a benefit out of it: they all got to put "AngularJS" on their resume.

[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!

This post originally appeared on The Daily WTF.

Leave a Reply

Your email address will not be published.