Binding in the view or the controller?
Posted
by
da_b0uncer
on Programmers
See other posts from Programmers
or by da_b0uncer
Published on 2012-09-03T09:01:16Z
Indexed on
2012/09/03
15:51 UTC
Read the original article
Hit count: 218
web-development
|mvc
I've seen 2 different approaches with MVC on the web.
One, like in ExtJS, is to bind the callbacks to the view via the controller. Finding every element on the view and adding the functionallity.
The other, like in angular.js and in the lift-framework server-side, too, is to bind in the views and just write the functionallity in the controller.
Which is better and cleaner?
The ExtJS approach has dumb views and all the logic in the controller. Which seems clean to me. I had problems with global IDs for GUI-elements or relative navigation to GUI-elements in this approach. When I changed the view, the controller couldn't find the buttons anymore or I had multiple instances of one button with the same ID on a single application, because of the global ID.
But I solved this with IDs that are only global in a view and can be on the application multiple times. So I could mess with the (dumb) views layout and design and the functionallity wouldn't break.
The angular.js approach with the bindings in the view don't has the problem with global IDs. Also, the person who changes something in the view layout has to know the IDs anyway, so the controller can put the data at the right spot.
So if I write
<a ng-click="doThis()" />
for angular.js and implement doThis()
or
<a lid="buttonwhichdoesthis" />
for extjs and find the element with the local id and add doThis()
as handler on the controller side, seems to be not so different.
The only thing is, the second one has one more layer of indirection, which seems cleaner.
The first one seems somehow to cost less effort.
© Programmers or respective owner