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

Show parent comments

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.