Hacker News new | ask | show | jobs
by chidevguy 4586 days ago
One thing that I like about Knockout is that you can easily drop it into a legacy site, allowing you to have some pages that use it and others that don't. Forgive my naivete, but is this something that is easy to do with Ember or Angular as well?
7 comments

Angular yes, Ember perhaps not. I this wrote briefly on the subject recently: http://adambard.com/blog/angular-in-the-small/
Ember yes.
Angular definitely not.
I've been working on porting mission critical parts of a 10-year-old+ app over to Angular; some of the syntax is clunky but it's definitely doable
in-co-rrect
EDIT: whoops, I was answering about Knockout vs Angular here, not Ember.

I think it's actually easier in angular, because you can set the ng-app parameter at the point in the DOM tree you want to bind to the Angular portion of the app. (ng-app is similar to ko.applyBindings, except that unlike KO, with Angular don't have to worry about having parent DOM bindings clash with child DOM binding applications.).

I have successfully done this with Angular. It was easy and convenient. No idea about Ember, so far I've only watched its tutorial video.
see an example of using emberjs for only some pages: http://www.ryandao.net/portal/content/emberjs-how-use-ember-...
this is one of the nice things about angular. You can just drop it in to make a component of an existing site use angular. I attempted to get that to work with ember, but I don't think it's possible.
It is possible, and just as easy with Ember.
Yes. Both Angular and Ember support this pattern pretty effortlessly.
Without knowing the specifics, the best answer I can come up with here is that it's Javascript -- so yeah, you can write it affect parts of the page, or all of the page. You can have it control just the navigation bar on a site, or the whole site altogether.

There are caveats here -- if you have the library loaded from any page with html5 location mode enabled, it'll take over link-handling on those pages. With Angular, it's easy to circumvent by adding a 'target' attribute to the links, but on a legacy site, that might mean having to touch every page that Angular doesn't already exist on, which would be a chore.

The alternative is to not enable HTML5 location mode (so links are to #/link/) or to adjust the targets on links that aren't meant to be handled by JS.

All summed up though, while it may not be written anywhere, I've always gotten the feeling that Angular prefers to own the entire page, loading partials into views where appropriate, and using separate controllers for other portions of the page. That said, it can work either way, but does take some extra special care.

"allowing you to have some pages that use it and others that don't"

Your response seems to dig into a different (though related) issue. If the question is whether, given a whole website, whether angular/ember can exist only on certain pages, but not all pages, then the answer is Yes.