-
Notifications
You must be signed in to change notification settings - Fork 703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ng-bind vs curly brackets #41
Comments
I use Leave this issue open and I'll get it added + close it. |
Are there any specific use case for when to use {{}} and when to use ng-bind? |
Probably, ng-bind is a good use case when you have a syntax conflict, like with laravels blade templates. |
I was thinking more in terms of performance. :) |
I always use Also, Angular doesn't evaluate the entire surrounding of the expression (https://speakerdeck.com/toddmotto/angularjs-the-performance-parts?slide=57) - see final example here. |
IGOR MINAR SAYS: ng-bind is faster because it’s simpler. interpolation has to go through extra steps of verifying context, jsonification of values and more. that makes it slightly slower. ... from [the same link you cite]((http://ng-perf.com/2014/10/30/tip-4-ng-bind-is-faster-than-expression-bind-and-one-time-bind). Given Igor's authority, I'd be loathe to worry about this ... and I don't believe we should be recommending |
Now we're talking... these were the answers I was looking for! 👍 :) |
Can't say I agree that it would hinder productivity in any shape or form unless you can elaborate @wardbell ? Sticking with one syntax IMO only makes it easier for a few reasons:
Benefits to
I don't think it's a "premature optimisation" to use a syntax that's more inline with every other Be sensible and stick with your conventions - but understand them to be able to make your own judgment :) |
Different stroke for different folks I guess. I measure productivity in part by what contributes to ease of reading, writing, and maintenance. 9 out of 10 doctors agree that the following is easier to read and write
than
Certainly took me less time and fewer mistakes to write while in a moving vehicle driving to Thanksgiving dinner 😃 I can count on one hand the number of times that Nor have I once heard someone complain about the "inconsistency" of interpolation and But let's not fight. This isn't going to be a big deal one way or the other.We've made our points. Let's go out enjoy the day. Peace out! |
As the guide recommends the use of one-time binding, where appropriate, is there a one-time version of The Angular documentation for ngBind indicates a preference for the mustache syntax, but provides some caveats:
Finally, @wardbell: I would be more likely to write your example as follows, which is, at least, somewhat more attractive: <span ng-bind="ctrl.name"></span> is my hero! |
Indeed you can. Just do something like: ng-bind="::prop" And you're good to go :)
|
Hey guys- is the performance argument still valid? This benchmark appears to show handlebars as 20% faster than bind. Curious if something has changed in recent versions. |
Hi everybody!
I read this guide and try to follow advices contained here, but today I faced problem with curly brackets, because I had JS imports in
<footer>
element at bottom of page - I had to move it to<head>
section and useng-cloak
on body (which isn't adviced... But works 😄 ). Then I found ngBind directive, which completely removes this problem. As I googled, it is also faster than{{}}
but some people are complaining that it created unnecessary boxing with<span ng-bind="something"></span>
and isn't as clear as curly brackets syntax (maybe it's only old habit?). I am curious of your opinion - maybe it's worth mentioning in @toddmotto's / @johnpapa's styleguides?The text was updated successfully, but these errors were encountered: