Hacker News new | ask | show | jobs
by MrOrelliOReilly 4261 days ago
Very helpful. I've unsuccessfully search for a way to do one-time binding before in a data intensive application and never came across the {{::ctrl.foobar}} syntax.

One thing I'm hesitant about is their advice to use directives instead of ng-controller="MyCtrl". Since controllers really are app specific glue code I rarely find myself wanting to reuse them - what advantages are directives supposed to give here?

3 comments

You can easily get one-time bindings using https://github.com/kseamon/fast-bind, which supports not only one-time bindings but also updating a binding only when called.

This makes it easy to work with data that doesn't change, promises, or large amounts of data that rarely changes.

Karl Seamon did a great talk about performance this past January at ng-conf as well, https://www.youtube.com/watch?v=zyYpHIOrk_Y

Yeah that was a great talk, definitely worth watching for those looking for ways to improve the performance of their Angular apps. Do you know of any other videos like that? I've searched in the past but haven't come up with much (especially not for stuff relevant to latest versions of Angular)
I haven't really found any videos as comprehensive as this, just blog posts or videos that discuss one topic/strategy at a time. Outside of this video, there doesn't seem to be an authoritative or even comprehensive list of what can be done to speed up applications.

As to newer stuff, I believe Karl is specifically talking about 1.2 (might of been a release candidate or beta at the time) so his talk should be applicable to the newest stable version, and I've found that to be true so far.

As an aside, and I haven't objectively measured it or even really investigated it, it seems angular's 1.x stable versions aren't coming out as fast as they once did (it feels like 1.3 has been in rc/beta forever and 2.0 doesn't even seem to be out of the planning stages). So at this point I think 1.3 stable will be released in the next few months and hopefully they will have an updated talk on performance at the next ng-conf in March.

Yeah unfortunately 1.3 drops support for IE8 which sadly makes it inappropriate for our production app for the time being. Which is a shame because it looks to have a tonne of performance fixes and bind-once built in which would have been nice, to avoid using a 3rd party module.
Directives are more powerful - for example, child directives can require the parent directive's controller and make use of it, which can lead to some powerful control flow.

You can also define a controller and have the directive consume it via named reference - here is one example that makes use of this: https://github.com/driftyco/ionic/blob/master/js/angular/dir...

Controllers should be consumed this way, so that they become easier to test. Testing directives can get complicated.

One-time binding is a 1.3.0 beta feature (check your version before using)!