angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

Allow binding to getter/setter fn

Open vojtajina opened this issue 14 years ago • 47 comments

Now, when we have "accessor" locals, one should be able to bind to accessor. So either $parse or ng-model shoul handle it.

This is ugly - with binding to getter/setter, I wouldn't have to do the extra "value" and copying back and forward: http://jsfiddle.net/vojtajina/XuhzP/64/

The tpl of the component would be just:

<span ng-hide="editMode" ng-click="editMode=true">{{model()}}</span>
<input type="text" ng-model="model" ng-show="editMode" ng-enter="editMode=false" />

Another ugly solution (taking advantage of obj reference from parent scope): http://jsfiddle.net/vojtajina/XuhzP/65/

vojtajina avatar Mar 05 '12 01:03 vojtajina

+1 this provides real encapsulation so that our models are clean.

tombburnell avatar Apr 23 '13 16:04 tombburnell

+1 I really need this too - actually the getter more than the setter, but both would be handy.

bartread avatar Apr 26 '13 22:04 bartread

+1 any solutions?

sskyy avatar Apr 29 '13 04:04 sskyy

+1 for getter and setter as ng-model

max-l avatar May 06 '13 19:05 max-l

+1

Undistraction avatar May 17 '13 10:05 Undistraction

+1 es5 get/set work, but for ng-model we need a solution

geierwally avatar May 23 '13 15:05 geierwally

+1

gaevoy avatar Jun 16 '13 12:06 gaevoy

+1

markushausammann avatar Jun 19 '13 19:06 markushausammann

+1

petmongrels avatar Jun 24 '13 14:06 petmongrels

+1

m-j avatar Jul 04 '13 10:07 m-j

:+1:

wajda avatar Jul 07 '13 23:07 wajda

+1

shangxiao avatar Jul 08 '13 10:07 shangxiao

+1

mikalaj-murziankou avatar Jul 11 '13 17:07 mikalaj-murziankou

+1 here as well. I have been using Angular for just a short period of time, and I am already hitting this limitation. My use case is that I have a backend service returning a JSON that has very minimal, generic values, which must be compared against a core data structure the app brings in from a service at run time. I then want to take my models and parse them through a wrapper function which does the following:

  • compares the values of my model against their appropriate structures in core, returning readable, view-ready values
  • provides a public API for get/set the model data against core

So my wrapper object would perform all operations on the actual model, angular would only be responsible for calling the public API instead of working directly on my model, but still retain the ability to bind to data.

Ultimately, the point is that all of this parsing could be handled on the backend at the time we a GET or POST is received, but, we're talking about Client-side SPA frameworks here - shouldn't we move that work into the client's browser? Why should my precious little server have to work so hard if the users browser can do it themselves? :)

netpoetica avatar Aug 16 '13 02:08 netpoetica

:+1:

terwey avatar Dec 13 '13 15:12 terwey

+1

dberringer avatar Jan 03 '14 02:01 dberringer

I would love a solution that is flexible enough to handle mori (Clojure immutable data structures ported to JS) or ProtoBuf.js in addition to standard getter/setters.

In particular, mori's immutable data structures would probably make change detection very efficient.

inklesspen avatar Jan 06 '14 17:01 inklesspen

+1

gauravmeena0708 avatar Jan 17 '14 18:01 gauravmeena0708

+1

piotrplenik avatar Mar 05 '14 09:03 piotrplenik

+1

gabzim avatar Mar 14 '14 11:03 gabzim