r/angularjs • • Dec 11 '13

Angular would be great for super-responsive layouts except it doesn't work in IE

Edit: Solved! Thanks Evereal!

Check it out

Here it is being used on site I'm working on (ignore the sluggish masonry, I'm working on it).

Look! Responsive images:

http://i.embed.ly/1/display/crop?height={{(1000 * window_width/ 2 * retina) | decimal}}&width={{(1000 * window_width* retina) | decimal}}&url={{topstory.image}}&key=jlakjflakjflakjfal;kja;lkja;lkjalkj

('retina' = 2 if it's a retina display, 1 if it's not)

Pretty neat, huh? You can get a perfect layout on any screen right down to the last pixel. EXCEPT IT DOESN'T WORK IN IE.

Here's the issue

I guess I'm hoping someone has a solution to the IE bug, because to me this is so much cooler than css media queries. I'm considering telling IE users to just fuck off.

2 Upvotes

20 comments sorted by

8

u/evereal Dec 11 '13 edited Dec 11 '13

Hang on, the only thing IE doesn't like is templates within regular style attributes (not ngStyle).

If you replace your:

style="width: {{(1000 * window_width) | decimal}}px; font-size: {{(40 * window_width) | decimal}}px;"

with:

ng-style="{width: ((1000 * window_width) | decimal), 'font-size': ((40 * window_width) | decimal)}"

It works fine in IE. Use ngStyle, not regular style attributes when you want to get fancy and dynamic with styles! That's what it was made for!

However, I still wouldn't recommend it in this case. Frequent digest cycles (like when someone is resizing your app) can have a significant performance impact once your app is non-trivial. It's not a "couple of calculations, big deal" as you put it.

-1

u/InterwebCountyPress Dec 11 '13

Did you try it with the plunkr? I don't think ngStyle works, it doesn't seem to do calculations like that but you might be able to use ng-style = "thiselementstyle()" and write a function for every element.

And it seems to be working fine on this with 300 separate stories resizing at once. The js masonry was killing it though, I switched to a CSS version and it's running better. Who sits there resizing their browser all day anyway?

5

u/evereal Dec 11 '13 edited Dec 11 '13

Yes, I tried it with the plunkr, yes ngStyle works. No, you don't need to use a function.

See: http://plnkr.co/edit/Boy09W1QNkvJXGTU6P2j?p=preview

And no, I still wouldn't recommend this.

-3

u/InterwebCountyPress Dec 11 '13

Woohoo! Thank you! I'm going to post that plunkr over in the github issue queue if you don't mind.

And I'm using it, sensible advice disregarded! haha

3

u/evereal Dec 11 '13 edited Dec 11 '13

The very first comment in the github issue is "Use ngStyle". My example is exactly what they mean. Some people complain that it's a work-around, but it is actually the correct, cleaner way to do this kind of thing.

-1

u/InterwebCountyPress Dec 11 '13

I guess the syntax was stumping me and the others in there.

6

u/mnsota Dec 11 '13

Please edit your post with SOLVED and the solution so the rest of us don't have to fall down this ladder of comments. Thanks!

5

u/[deleted] Dec 11 '13

Works in IE 11 so the good news is, it will have wide corporate adoption in 2021.

0

u/InterwebCountyPress Dec 11 '13

Ah ha ha it doesn't work in IE11 either.

0

u/madsonm Dec 11 '13

This guy must be a Microsoft employee with such aggressive figures.

3

u/ozzilee Dec 11 '13

So every time a user resizes their screen, you go through a digest cycle?

Doing layout with JS is a bad idea. Doing it with Angular has to be one of the worst ideas I've seen.

-2

u/InterwebCountyPress Dec 11 '13

A couple calculations when you resize the browser, big deal.

11

u/mvg210 Dec 11 '13

Just tell them to fuck off

7

u/[deleted] Dec 11 '13

Tell them to fuck off.

Seriously though, just let them know that you can't guarantee 100% of functionality if they use IE but don't prevent them from using it. I know of several corporate sites where IE is the standard and installing Firefox or Chrome is seriously frowned upon or just plain prevented.

Let's hope that either the Angular or IE teams can address it in future.

This comes from someone whose front end is Angular and back-end is 100% .Net/SQL Server on Azure.

5

u/zomgwtfbbq Dec 11 '13

Wtf guys, why is everyone downvoting OP? This is his topic, he's contributing to the discussion, he's not trolling. Stop being douchey. If you think what he's doing is bad, leave a comment. Empty downvotes aren't helpful in a programming thread.

1

u/mvg210 Dec 11 '13

Are you planning to have a mobile view?

-1

u/InterwebCountyPress Dec 11 '13

Probably, but it's pretty readable on my iPhone, just slow as hell.

4

u/TheAceOfHearts Dec 11 '13

Don't do this. Doing styling with JavaScript is slow and generally considered a bad practice. CSS is a pain, but it's also (usually) hardware accelerated.

-1

u/pateras Dec 11 '13

So glad I don't have to support that garbage browser.

0

u/[deleted] Dec 11 '13

[deleted]