HTML5 Zone is brought to you in partnership with:

Sarah is a Content Curator at DZone. She lives in Knightdale, NC and enjoys spending her free time reading, crocheting, and playing PC games. Sarah has posted 37 posts at DZone. You can read more from them at their website. View Full User Profile

The Unstable Future of Angular.js

03.24.2014
| 21108 views |
  • submit to reddit

Google's overwhelmingly successful dynamic HTML enhancement, Angular.js, has a flaw that could limit the platform's longevity. While there is nothing inherently wrong about Dependency Injection systems, Adrian Rossouw's recent post explains how some instructions given in the developer's manual cause minification to break down when encountering certain functions. Rossouw states:

The reason that it breaks minification, is that is using some really clever trickery to abuse parts of the javascript language, to do things that conflict with the fundamentals of the language itself.

Specifically, it uses Function.prototype.toString(), to read the source code of the function that is being called, and extract the names that the parameters were given in your source. Because minification changes those variable names, it can no longer rely on that to work.

The following video illustrates exactly how Angular.js breaks in this situation:

It is odd that such a bizarre occurrence exists in an otherwise beautifully constructed platform. Even more baffling is the fact that this option is first in a list of three ways to accomplish the exact same task, and the other two options are perfectly fine. Rossouw provides a colorful explanation of this issue:

On your first day at a new company, you are offered the use of one of three company cars.

As you slip into the red car nearest you, you notice a small sign on the dashboard saying “warning: red cars will explode violently on wednesdays”.

I worry about the fact that something like this is just accepted and people have decided that it’s easier to just warn others about the exploding cars rather than just not giving people exploding cars to begin with. This is expounded by the fact that there are two other perfectly working cars, which might not be your favorite color, but at least they won’t kill you.

The developers of Angular.js agree that this "black magic" is a problem, and have said that the issue will be fixed in the upcoming Angular.js 2.0.

Published at DZone with permission of its author, Sarah Ervin.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Keith Moore replied on Mon, 2014/03/24 - 8:05pm

Good points.  At least there are a couple of workarounds for this so that you can still minimize your code.  http://docs.angularjs.org/tutorial/step_05

There is also ngMin as an option.  Version 2.0 is going to address this anyway.   So why do you think this would cause an unstable future for Angular.js?  Its 

Sarah Ervin replied on Tue, 2014/03/25 - 9:59am

 Thank you for the link to the workarounds. :)

The author who was cited in the post also discusses ngMin and how the need for such a tool leads to more problems down the road. Everything from "Tooling as a Workaround" to "Finding a Middle Road" discusses these issues.

Because the developers have said they are planning to fix this issue in 2.0, the future is looking much brighter. However, it is very interesting to note the way that such an extraordinary flaw made it not just into the user manual, but to the top of the list. Hopefully there will not be other instances that follow suit.

Mark Volkmann replied on Wed, 2014/03/26 - 2:59pm

I think it's wrong to characterize this as a flaw. Many people are successfully using AngularJS just fine with dependency injection working this way. It's just the best approach they had to DI at the time. As you have noted, AngularJS 2.0 has a better implementation.

What upsets me most about this article is the over-dramatic title. Clearly it was meant to draw attention rather that discuss real issues.

Robin Bygrave replied on Wed, 2014/03/26 - 3:46pm

+1 on Mark Volkmann's comment. Just to add some links on Dependency Injection v2:

https://github.com/angular/di.js

Slide presentation on it:

https://dl.dropboxusercontent.com/u/36607830/talks/ng-conf-di-v2-annotated.pdf


Mailou Hua replied on Fri, 2014/04/25 - 9:18am

 Wonderfull points,i am agree with that  http://www.replicabagsshoes.com/

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.