The Daily WTF
Dora‘s AngularJS team (previously) wanted to have their display be “smart” enough to handle whether or not you were editing a list of “Users” or just one “User”, so they implemented a function to turn a plural word into a singular word.
Which, of course, we already know the WTF implementation of it: they just chop off the last letter. So “Potatoes” becomes “Potatoe”, “Moose” becomes the noise cows make, and I’m just left saying “oh, gees”. But they managed to make it worse than that.
The actual display might be used like so:
<label> Edit {{$ctrl.singular}}</label>
singular is a property on the controller for this component. But how does that get populated?
function getSingular(){ if($ctrl.type){ $ctrl.singular = $ctrl.type === ‘details’ ? $ctrl.type : $ctrl.type.slice(0, -1); } }
So, it’s important to note, getSingular isn’t a “get” method in the conventional sense. It populates the singular property, but
To read the full article click on the 'post' link at the top.