r/javascript • • Nov 05 '14

AngularJS: The bad parts

http://larseidnes.com/2014/11/05/angularjs-the-bad-parts/
87 Upvotes

88 comments sorted by

View all comments

28

u/yelvert Nov 05 '14 edited Nov 05 '14

1 obj should be defined somewhere in JS not just HTML, if for no other reason than clarity, if you do this both fields work exactly as expected.

2a Use the array/$inject declaration syntax

2b Use a build process you fool, ng-min solves your minification woes. You should ALWAYS have a build process anyways.

3 I work on an extremely large/complex angular app with 500-2000 active bindings at any one time, and have NEVER run into any issues at all with the digest loop. It is always extremely fast, even on slow computers.

4 Dont be a dumbass

5 Repeat #4

Edit. There IS one downside to angular scopes, and that is the need to occasionally/rarely using $parent in ng-model to force it to look into an "outer" scope, but I've found that whenever I run into this issue, its usually because I didn't design something right.

8

u/Gundersen Nov 05 '14

The really unfortunate thing about 2a is that it is as close as you could get to AMD without using AMD. Imagine all of the libraries that would instantly be available to angular if only it used the AMD syntax

1

u/enkideridu Nov 06 '14

Sounds like you might not be using Browserify in your build process. Try it out, it works with angular pretty well. (Most AMD libraries also support the CommonJS format)

1

u/[deleted] Nov 06 '14

This is a completely non-existent argument.

All those libraries are still available.

0

u/yelvert Nov 05 '14

We don't use AMD, or requirejs for that matter. So I can't really comment on this, other than pointing out that, to my knowledge, Ember/Backbone/React/etc don't "integrate" with AMD/require natively either, and that's arguably a good thing, as it would lock you into an additional dependency you may not want.

3

u/adrianmiu Nov 06 '14

"1 obj should be defined somewhere in JS not just HTML, if for no other reason than clarity, if you do this both fields work exactly as expected."

And everybody knows just how easy that would make the entire development process in a non-trivial app (you know, the one angular claims it helps develop)

"3 I work on an extremely large/complex angular app with 500-2000 active bindings at any one time, and have NEVER run into any issues at all with the digest loop. It is always extremely fast, even on slow computers."

The article said it's easy to exceed 2000. I did it too. Also I recommend setting breakpoints in functions and what how many times it is executed during a digest-repaint cycle. Such fun!

"4 Dont be a dumbass"

Do as the priest says...

6

u/Poop_is_Food Nov 06 '14

At this point, I imagine some readers are eager to tell me how to avoid the above problem. Indeed, when you know about the problem, you can avoid it. The problem is that a new Angular user likely does not know about the problem, and the default, easiest thing to do leads to problems.

Angular is ok if you know it well and all of your team members know it well. But if you have to bring on some people to help out in a pinch, and they havent already crested the huge learning curve, then you're fucked.

1

u/[deleted] Nov 06 '14

Huge learning curve?

I was building with AngularJs after a couple of hours, don't overblow the difficulty.

It's really not very hard.

12

u/Poop_is_Food Nov 06 '14

It's not hard to build something after a couple hours. It gets hard when you need to do things out of the ordinary, such as keeping track of the actual DOM updates that angular is doing.

2

u/Cintax Nov 06 '14

Out of curiosity, why would you ever need to do that? Doesn't that village the core premise of MV*?

10

u/Poop_is_Food Nov 06 '14 edited Nov 06 '14

Well let's say you have a modal, and the positioning of the modal depends on its height. If it's taller than the viewport then you position it 100 px from the top of the window and then scroll. If it's shorter than the viewport the you center it vertically. You need to measure the height of the modal. And you can't measure it until it's actually in the DOM. And if angular is in charge of appending it and populating its content, then it's very hard to tell when that process is complete.

edit: why downvotes?

6

u/pleadub Nov 06 '14

If it isn't already the modal should be refactored into a directive. Then all of the manipulation can be handled in the postLink function on the directive definition object for the modal.

Now whenever the modal's open event is triggered you can use the element argument which is passed to the postLink function to grab the height of the modal. You could then use the angular services $document and $window to grab the height of the viewport with

h = Math.max($document[0].documentElement.clientHeight,   $window.innerHeight || 0);

And you could also set up a listener on resize so you can update the modal there as well.

This all comes back to your first point of needing to know the tool you're using well.

3

u/JonDum Nov 06 '14

And all that cruft is why Angular gets a rep for being overly complex.

3

u/Poop_is_Food Nov 06 '14

Thanks for proving my point?

2

u/[deleted] Nov 06 '14

[removed] — view removed comment

1

u/Poop_is_Food Nov 06 '14

Yes, thank you that is the issue thread I was looking for but I couldnt find it. When I first read that, it was the beginning end of angular for me. In particular this quote:

I agree that some jQuery plugins may be hard to integrate, but those are usually the ones that do not have a clear separation of concerns. Those plugins are typically best rewritten anyway, as they are typically not performant nor maintainable in the long run.

I've encountered this kind of attitude a few times from angular contributors and it's a big turnoff for me. "Angular cannot fail. It can only be failed."

2

u/ganarajpr Nov 06 '14

This problem has nothing to do with Angular and has everything to do with thinking in terms of views than models. Also, thinking in terms of individual elements than thinking in terms of selectors - which is how you would have solved it before angular.

I wont provide you a solution to this problem here. But know that there IS a solution. You just have to think about it without considering a css selector.

1

u/Poop_is_Food Nov 06 '14 edited Nov 06 '14

Did you respond to the wrong comment? Not sure what selectors and models have to do with this. I said "modal" not "model."

And yes I know there is a solution. I've found the solution and it was a pain in the ass which is why I used it as an example.

2

u/[deleted] Nov 06 '14

is that easy in any MVVM framework?

1

u/Poop_is_Food Nov 06 '14

It's that easy in Marionette. And if you dont consider that a framework, well then it's easier without a framework.

1

u/yelvert Nov 06 '14

Not true at all. Several months ago we had a data guy, with no programming experience, that was coming to me all the time to help improve his admin interface. We had already moved our main app to angular from backbone and had not started the admin migration. I took a day and setup the base framework for the new admin app, and showed him the full app code to learn from, 3 days later he had 2 of the admin areas done. Sure he made a few mistakes, but it was all there and worked well.

2

u/Poop_is_Food Nov 06 '14

wow that anecdote about your CRUD app negates my entire point.

1

u/yelvert Nov 06 '14

Ha, a bit more complicated than that. Those are staying in backbone ... for now.

→ More replies (1)