Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've done one project with ember and was very happy with it but I'm now working on a project where I only need parts of the page to be controlled by the framework. So far I'm loving the way angular integrates with the dom but once you get back to the controllers/directives it suddenly feels like I have to do a whole lot more work than with ember. The main difference seems to be that you have to manage updates yourself i.e. use $watch or trigger them yourself by binding to js event. At this point I'm kind of wishing their was an embular project ( :) ) that integrated with the dom the way angular does but had ember's awesome binding/computed properties...


Can you give an example of where you've had to use $watch? Usually too many $watch is an indication that you could improve your app's architecture, e.g. by abstracting into directives.

FWIW I'm only speaking from personal experience and in your case lots of $watch might be necessary.


A good example is where I have a list of items which is filtered by a select[1]. I have the select wired up to the controller with a two-way binding and the controller watches for changes to the binding and filters the list accordingly. Maybe this isn't an idiomatic way to do it?

[1] http://plnkr.co/edit/ykfblPHlwkBJyMeObFyV?p=preview


Here's your example without a watch: http://plnkr.co/edit/GCv7bQALiOTgJ0npavwi?p=preview


That looks interesting, so does the filter reevaluate automatically when any of the variables used in the expression change?

edit: and thanks a lot for taking the time to look at it!


Ah, so I see that anything associated to the scope is reavaluated whenever anything else in the scope changes. Here's a further modification based on yours that keeps the criteria on the controller.

[1] http://plnkr.co/edit/JYyUvyh30e5L9KwVjDW2?p=preview

[2] http://plnkr.co/edit/ffYb14JjgSip5BTITILS?p=preview

edit: much happier with this version than the one I started with, thanks

edit: added example [2] which doesn't require a watch but still uses the service to do the filtering (because in my app it's actually an ajax call)


I haven't had to use $watch except to integrate with jQuery plugins for fancy widgets (and wish I could get rid of those). For everything else, two-way binding in Angular works very well.


From my vague understanding, I've heard knockout described as similar to your desired "embular"


I've actually just inherited a giant mess of knockoutthat i was looking to replace with angular. I have to admit that I was actually expecting angular to handle this kind of stuff so I'm a little disappointed in that respect. Angular does seem to have plenty of benefits but I thin i'll give knockout a full review before(maybe it just needs to be structured better).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: